Page 1 of 1

input text array validation in jquery

Posted: Fri Apr 17, 2009 1:11 am
by pcoder
Hi All,
I am using jquery to validate the form. But i got a problem to validate completely. Somewhere i have an element like:
<select name="relation_cd[]" id="relation_cd">
</selelct>
<select name="relation_cd[]" id="relation_cd">
</selelct>
Which comes from database dynamically.
Is there any technique to validate such kind of element in jquery?
I didn't find the way to validate. I am new to jquery even i don't know how to add the custom validation function so that i can validate the form completely.
Hope, i will get some suggestion from you guys.

Thanks

Re: input text array validation in jquery

Posted: Fri Apr 17, 2009 1:43 am
by charlestide
i have not found any rule for your validator, so i can just tell you how to select those elements.

Code: Select all

 
$('select[@name^=relation_cd]').change(function(){
//here is your validating code
});
 
the function will occur when all of SELECT tags that NAME start with relation_cd. but i have no test for this. if it not work, may be you could add your own attribuates to the SELECT, such as <select name="relation_cd[]" use="validator">

my english is poor, hope you can understand what i said

Re: input text array validation in jquery

Posted: Fri Apr 17, 2009 10:34 am
by pickle
Your code is invalid. You can't have 2 elements with the same ID. ID must be unique.

Re: input text array validation in jquery

Posted: Sat Apr 18, 2009 11:13 pm
by pcoder
Thanks for your reply guys.
Your code is invalid. You can't have 2 elements with the same ID. ID must be unique.
Currently, ID is use less, it used name for the validation.
I couldn't validate it using jquery. Still finding the way to validate it.
Thanks

Re: input text array validation in jquery

Posted: Sun Apr 19, 2009 6:06 pm
by kaszu
From jQuery documentation
Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again.
Correct selector will be

Code: Select all

select[name^=relation_cd]