[jQuery] Better way to select parent form?
I'm trying to write a script that responds to a keyup event in any field of a
given form. If the form is valid, the submit button of that form is enabled.
The problem is that there are several forms on the page. My script has to
enable the right one.
I have a way that works, but it's complicated. Can someone suggest a better
way?
The essence is that I first get the "name" attribute of the form with
"this.form.name". Then I use the name in a jQuery selector...
$('form[@name=' + formName + '] input[@type=submit]')
Here it is with some context...
Bind the keyup function...
$(document).ready(function(){
$("form :input").keyup(function(){
updateFormEnabled(this.form.name);
});
}
function updateFormEnabled(formName)
{
if (isFormValid(formName))
{
$('form[@name=' + formName + ']
input[@type=submit]').removeAttr("disabled");
$('form[@name=' + formName + ']
input[@type=submit]').removeClass('formfielddisabled');
} else {
$('form[@name=' + formName + '] input[@type=submit]').remove();
$('td#submit_td_' + formName).append("<input class='ordinaryButton
formfielddisabled' disabled='disabled' name='commit' type='submit'
value='Add user' />");
}
}
The isFormValid(formName) function also uses the same way of finding which
form to examine.
--
View this message in context: http://www.nabble.com/Better-way-to-select-parent-form--tf4107139s15494.html#a11679516
Sent from the JQuery mailing list archive at Nabble.com.