Here is my javaScript:
<script type="text/javascript">
$(function () {
$('#first_name, #second_name, #third_name, #fourth_name').bind("change keyup",
function () {
if ($("#first_name").val() && $("#second_name").val() != "" && $("#third_name").val() != "" && $("#fourth_name").val() != "")
$(this).closest("form").find(":submit").removeAttr("disabled");
else
$(this).closest("form").find(":submit").attr("disabled", "disabled");
});
});
</script>
And here is my HTML:
<form method="post" id="myForm" name="myForm">
<div id="terms_area">
<ul>
<li>
<label>Print your name</label>
<input id="first_name" type="text" />
</li>
<li>
<label>Print your surname</label>
<input id="second_name" type="text" />
</li>
<li>
<label>Print your surname</label>
<input id="third_name" type="text" />
</li>
<li>
<label>Print your surname</label>
<input id="fourth_name" type="text" />
</li>
</ul>
<center>
<input class="terms_button" type="submit" value="I accept the terms of this agreement" disabled title="please fill in all required fields to accept the terms" />
</center>
</div>
</form>
Is there any way I can get the JavaScript to target the form name of 'myForm' as I have multiple forms on one page?
$('#myForm').find(":submit").removeAttr("disabled")?!= ""after$("#first_name").val()$('#formId #childid')(but you shouldn't be re-using ids anyway).$("#first_name").val()will always evaluate totrue(or truthy), even if it's only an empty string. Incidentally, while we can all read your code and guess what it is that you're trying to do, it's better (and, really, a requirement) that you explain what it is that you're trying to do.