Help in jquery loop |
[eluser]Techno Heart[/eluser]
Hi all, I used a php for loop to create a block in html page.the block has six fields.in javascript page i have to validate that block.(i.e) if any one field among six is empty then it should show alert message.i have written conditions as follows Code: var from_month = $("select[id='from_month']").map(function(){return $(this).val();}).get(); now i am writing condition as Code: for(var i=0;i<3;i++) if i write conditions like this the number of lines of code is more.so any one have idea to make it simple using same loop.?
[eluser]Flemming[/eluser]
could you give us a 'bigger picture' of what you're doing? Is it client-side validation?
[eluser]danmontgomery[/eluser]
jQuery uses CSS style selectors, there's no reason to do: Code: $("select[id='from_month']") When you can do: Code: $("select#from_month") I would just give a class like "required" to each element and check the value of all required fields Code: $('.required').each( function() {
[eluser]Techno Heart[/eluser]
Yes it is client side validation.Actually in html using php for loop i created 3 div which has six fields each.using jquery i got those values as array as given above. the text box values by default will be their label names i.e(Month,Year.etc).So if user fills any one field in on div block and if he try to submit the form then it should show alert.How to validate other than the code i given above.i want simple way. using each loop also not possible.
[eluser]Flemming[/eluser]
have you looked a jquery.validate()? http://docs.jquery.com/Plugins/Validation/validate this in my opinion is the best way to do any client side validation |
Welcome Guest, Not a member yet? Register Sign In |