Hello all,
First of all I really hope someone can help, this is probably (I’m hoping) really simple but I just can’t get it! I appreciate all the help thank you!
I am working on a form submit button, when it is clicked the first time it is disabled, so multiple submissions cannot occur before the confirmation page loads. There is also a checkForm function that validates the form ensuring that required fields are required.
Anyway I need to add an If statement so that if the function returns false (as in the form does not submit) then the button is re-enabled.
Hope this makes some sense, thanks in advance.
Jess
if(checkForm == false) {
$('#submit').removeAttr("disabled");
}
You should post the html code for button and the javascript function.
Tried this?
if ( some condition) {
$('#submit').attr('disabled', true);
}
else {
$('#submit').removeAttr('disabled');
}
felgall
September 3, 2010, 7:47pm
3
If checkform is the function whose return value you want to check then checking if it is false would use:
if(!checkForm()) {
Thanks for your responses folks, I’m still having some problems though. Here is the code I have:
<script type="text/javascript">
$(function() {
$('#submit').click(function() {
$(this).attr('disabled','disabled');
$('#loading').remove()
$('#submission').append('<img src="loading.gif" alt="Currently Loading" id="loading" />');
if(!checkForm()) {
$('#submit').removeAttr("disabled");
}
});
});
</script>
<form name="appForm" id="appForm" method="post" action="****" onsubmit="return checkForm()" enctype="multipart/form-data">
<input type="text" required="text" name="test" id="test"/>
<div id="submission"><input type="submit" name="submit" id="submit" value="Submit Application"/> <input type="reset" id="reset" name="reset" value="Clear Form"/>
<br/>
</div>
<span style="color:red;">*Please only submit this form once. You will be taken to a confirmation page once the form has been submitted.*</span>
</form>
wolken
September 4, 2010, 2:13pm
5
try this :
<script type="text/javascript">
$(function()
{
$('#appForm').submit(function() {
if(!checkForm())return false;
$('#submit').attr('disabled','disabled');
$('#loading').remove();
$('#submission').append('<img src="loading.gif" alt="Currently Loading" id="loading" />');
return true;
});
});
function checkForm()
{
return $('#test').attr('value') != '';
}
</script>
<form name="appForm" id="appForm" method="post" action="javascript:alert('submited');" enctype="multipart/form-data">
<input type="text" required="text" name="test" id="test"/>
<div id="submission"><input type="submit" name="submit" id="submit" value="Submit Application"/> <input type="reset" id="reset" name="reset" value="Clear Form"/>
<br/>
</div>
<span style="color:red;">*Please only submit this form once. You will be taken to a confirmation page once the form has been submitted.*</span>
</form>