Jörn Zaefferer escribió:
howa schrieb:
Hello, anyone has idea how to do dynamic form validation?
e.g. using
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
<input name="t1" type="text" />
<input name="t2" type="text" />
I only want to check for required field for t2 ONLY if t1 is equal to
some value
e.g.
If t1 = "test", then t2 cannot be null, else never mind abt t2
Try this:
$("...").validate({
rules: {
t2: { required: function(element) {
return element.value == "test"
}
}
}
});
By passing a function as the argument to the required-rule you can
specify whatever dependency you can think of. More examples can be
found here:
http://jquery.bassistance.de/api-browser/plugins.html#jQueryvalidatormethodsrequiredStringElementBooleanStringFunction
-- Jörn
How I can see the correct code would be:
$("#theform").validate({
rules:{
t2: {
required: function(element){
return $(t1).value == "test";
}
}
}
});
--
Best Regards,
José Francisco Rives Lirola <sevir1ATgmail.com>
SeViR CW · Computer Design
http://www.sevir.org
Murcia - Spain