Re: Quickform javascript rules

From: Date: Thu, 07 Aug 2003 11:46:34 +0000
Subject: Re: Quickform javascript rules
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-7080@lists.php.net to get a copy of this message
Hello, Quoting Alexey Borzov <borz_off@cs.msu.su>: > Mike Carter wrote: > > I've got two text fields on a Quickform and would like to ensure their > contents > > are equal upon submission. The twist is i want to do this test on the > client > > side, in javascript. > > > > How do i go about adding a javascript rule function to the Quickform? > > The same way as you add the server-side function... > 1) Write a JavaScript function for validation > 2) Register it via registerRule() > 3) Add a rule of this type with a 'client' modifier Okay... i've given it a go.. just for testing i've used the following javascirpt:- function js_compareStrings(string1, string2) { window.alert(string1 + " "+string2); return true; } $form->registerRule('compareStrings', 'function', 'js_compareStrings'); $form->addRule('emailConfirmGroup', 'emails dont match!', 'compareStrings', null, 'client'); The rule generates the javascript:- var field = frm.elements['emailConfirmGroup']; if (!js_compareStrings('emailConfirmGroup', value) && !errFlag['emailConfirmGroup']) { errFlag['emailConfirmGroup'] = true; _qfMsg = _qfMsg + '\n - emails dont match!'; } what is this 'value' variable that is being passed in to the js_compareStrings funciton? How do i go about knowing the form element names for two text boxes in order to pass them both to the javascript function? I realise that parameter 1 is infact a reference to the form text box which the rule is linked to. my javascript knowledge currently stinks :-/ Has anybody already successfully used a javscript function to check if two text boxes are equal as part of the validation? Thanks in advance, mike c. -- http://www.buddasworld.co.uk ---------------------------------------------- This mail sent through http://www.ukonline.net

« previous php.pear.general (#7080) next »