Mmmh: $this = $("#myinput"); $thisForm = $("form",$this.parent())
-----Original Message----- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of jarrod Sent: jeudi 19 juillet 2007 0:14 To: jquery-en@googlegroups.com Subject: [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... $('[EMAIL PROTECTED]' + formName + '] [EMAIL PROTECTED]') 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)) { $('[EMAIL PROTECTED]' + formName + '] [EMAIL PROTECTED]').removeAttr("disabled"); $('[EMAIL PROTECTED]' + formName + '] [EMAIL PROTECTED]').removeClass('formfielddisabled'); } else { $('[EMAIL PROTECTED]' + formName + '] [EMAIL PROTECTED]').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. Ce message Envoi est certifié sans virus connu. Analyse effectuée par AVG. Version: 7.5.476 / Base de données virus: 269.10.8/904 - Date: 16/07/2007 17:42