I'm fairly new to Jquery, so this might be a simple problem, but is there a way to hide the submit button on a form until all the fields have been validated.
The validation would need to be an 'as you type' solution. Basically I have 3 fields - first name, last name and e-mail. I'd like the submit button to stay hidden until the two 'name' fields have been filled in and a valid e-mail address has been entered into the e-mail field.
The form itself uses AJAX to input the form data into a database. The form is in a lightbox which should automatically close once the submit button is clicked.
You can see an example here: http://testing.xenongroupadmin.com/whatis/pfi
Ignore the 'Close this Window' link - that's just there for my convenience and will be removed in the final version.
Below is the HTML code for the form, followed by the JQuery/AJAX submission code:
<form id="registerform" action="thanks.php" method="POST">
<ul id="inputform">
<li>
<label for="firstname" id="firstnamelabel">First Name</label>
<input type="text" name="first_name" id="fname" class="registerboxes" />
</li>
<li>
<label for="lastname" id="lastnamelabel">Last Name</label>
<input type="text" name="last_name" id="lname" class="registerboxes" />
</li>
<li>
<label for="email" id="emaillabel">E-mail Address</label>
<input type="text" name="emailbox" id="email" class="registerboxes" />
</li>
</ul>
<input type="submit" value="Submit" id="emailbutton" />
</form>
And the Jquery:
$(document).ready(function(){
$("form#registerform").submit(function() {
var fname = $('#fname').attr('value');
var lname = $('#lname').attr('value');
var email = $('#email').attr('value');
$.ajax({
type: "POST",
url: "post.php",
data: "fname="+ fname +"& lname="+ lname +"& email="+ email,
success: function(){
$('div#register-panel, div#lightbox').fadeOut(300);
}
});
return false;
});
});
Thanks!