grey out submit button until form filled out
31,982
Jquery would do that. On the .keyup event have jquery check if both field's lengths are > 0 and change the button to be disabled or not.
$('#yourButton').button("disable");
$('.fields').bind('keyup', function() {
var nameLength = $("#sub_first_name").length;
var emailLength = $("#sub_email").length;
if (nameLength > 0 && emailLength > 0)
{
$('#yourButton').button("enable");
}
} );
Author by
samyb8
Updated on July 30, 2022Comments
-
samyb8 almost 2 years
I have the following form:
<form action="http://www.tahara.es/contact/subscribe.php" method="post" id="subscribe" name="subscribe"> <input type="hidden" name="action" value="subscribe"> <label>NAME:</label> <input type="text" name="name" class="Textbox" id="sub_first_name"> <label>EMAIL:</label> <input type="text" name="email" class="Textbox" id="sub_email"> <input type="submit" name="button" id="button" value="Subscribe" />
I would like to grey out the
submit
button until both fields in the form have been filled out. I guess jquery would do the trick?How can I do this, and where should I place the script?