I'm trying to disable submit button until some fields are filled. I've found a code working, but I have several forms in my page, so I'd like to select the form affected by the code...
html:
<form id="form_id1">
<fieldset>
<legend>Personal</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" /><br />
Address : <textarea size="30"></textarea><br />
</fieldset>
<input type="submit" value="Submit" />
</form>
<form id="form_id2">
<fieldset>
<legend>Personal</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" /><br />
Address : <textarea size="30"></textarea><br />
</fieldset>
<input type="submit" value="Submit" />
</form>
javascript:
$(document).ready(function()
{
$('input:submit').attr("disabled", true);
var textCounter = false;
$('input:text, textarea').keyup(check_submit);
function check_submit() {
$('input:text, textarea, select').each(function()
{
if ($(this).val().length == 0) {
textCounter = true;
return false;
}
else {
textCounter = false;
}
});
$('input:submit').attr("disabled", textCounter);
}
});
any idea? thanks
Ok, with the code #form_id1 input:submit before all fields it works on jsfiddle. But not on my page... I found that I'm using tinymce for textarea field, and that is the problem. The button is not activated after filling the textarea field! If I remove tinymce, it works! Any idea?
I've found that tinymce is using iframe for displaying its textarea :-(( is there a way to validate that?...