In this page we have one form element with input text and submit button. By default when we load the page submit button will be disabled and then if I type something in the input element submit button will be enabled. Here challenge is if user enter something and click on submit, the text that he has entered is remembered by the browser and next time if user select cached text instead of typing something how to enable the submit button with just one click.
<!DOCTYPE html>
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#firstName').keyup(function() {
var firstName = $(this).val();
if (firstName.length > 1) {
$('#submitBtn').attr('disabled', false);
} else {
$('#submitBtn').attr('disabled', true);
}
});
});
</script>
</head>
<body>
<form name="input" action="index.html" method="get" id='demoForm1'
autocomplete="on" method="post">
First name: <input type="text" id="firstName" name="FirstName"
value=""><br> <input type="submit" id='submitBtn'
value="Submit" disabled='true'>
</form>
</body>
</html>
Note: Please do not upgrade the Jquery and button should be enabled on select of cached data from input element.