Reputation: 4353
Im trying to hook up some validation for a site that im doing ... i have to admit, im not a jquery ninja.
So what i have done is taken validation from another site and added it to my site but it doesnt seem to be working.
My HTML is as follows
<label for="yourname">Your name</label>
<input type="text" name="yourname" id="yourname" /> <span class="error" style="width: 180px;"></span>
and a small fraction of the jquery that im using to validate is as follows:
if(!isString($.trim(iName.val()))){
iName.siblings('.error').text('Please enter your name.');
error = true;
}
The bit that its getting stuck on it the siblings bit ... when i run the code, it puts the error text behind every .error span on the page, where its only meant to put it on the .error span behind the current element.
Any help would be great.
Cheers
Upvotes: 0
Views: 96
Reputation: 1934
siblings
means all elements with the same parent with separator .error
and there is your peoblem. Using next
should solve it. Or placing every input with span in separate div.
Upvotes: 0
Reputation: 13599
If you just use the typical type of validation then I would recommend you to take a look at this plugin I think it simple and very easy to use.
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
Upvotes: 0