![]() |
How to validate select elements?
Dear All,
I have a list of select elements? Any idea how to validate them using jquery? |
Quote:
|
Dear ovTech,
Here is my link http://183.78.169.54/v3/addRoute.php. First you could press the add button maybe twice or three time. Then when you press submit button is where I want the validation to work. I want to make sure each element of select input is select. I have used the method class='required' is not working. Any help please? Quote:
|
One way, with or without jquery, is something like this.
1) When the submit button is clicked, loop through each row in the table. 2) At each row, use getElementsByTagName() to get all the <select>s in that row.3) Loop through the <select>s in 2) and check that the selectedIndex of each is > 0Without jquery, it should be only a handful of lines of code. |
Dear Bullant,
Here is my link http://183.78.169.54/v3/addRoute.php. First you can try to press the add button you will notice a new row of select box comes out. Now when you press submit is where I want to validate each row the select box should be selected. I have tried like this <select class='required' id='locationFrom[]' name='locationFrom[]' > but is not working. Any idea? So jquery will require more lines is it ? |
Quote:
In my earlier post I just described how I would validate the <select>s without jquery. I'm not a huge user of jquery and so in this case I'm not sure how many lines it would take. But without jquery it shouldn't take many. |
Quote:
http://docs.jquery.com/Plugins/Validation http://bassistance.de/jquery-plugins...in-validation/ |
Dear Ovtech,
I have some codes as you see in my function. I have also tried like this below but that is not function either. So I am stuck here. Code:
$('td:not(:first) select',form).each(function () {Code:
function setupFormValidation(form) { |
Dear Bullant,
How will you validate without jquery? Can you show me some coding snippet? Thank you. Quote:
|
Let's say your
Add button generates rows in the DOM similar to the ones in the demo below.When you click the Submit button, the cells containing invalid selections in their <select>s will have a red background colour.You can add as many rows and <select>s to each row as you like without having to touch the javascript. Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
Dear Bullant,
Is is possible to have error message below the select box. Another thing do you think I can use the jquery to build the dynamic select box rows and validate it via javascript which you have suggested? Will there be any conflict? Quote:
|
Quote:
Just make sure every time validateForm() is called, the error messages are not visible or do not exist, depending on which method to display them you use. Quote:
|
Dear Bullant,
Actually I am quite lost with this jquery.So when you said is prewritten javascript means we just call and use it is it? So once I have created the table and its row how via javascript I can add the message below the select box is that possible? How to do this "validateForm() is called, the error messages are not visible or do not exist, depending on which method to display them you use". I am bit confuse. Quote:
|
It sounds like you are trying to run before you can walk. Maybe first work through the w3schools javascript tutorials to learn the basics before playing with jquery.
Many people try to take the shortcut of using jquery without at least a basic understanding of the fundamentals of javascript and they consequently then keep running into problems or dead ends. |
Dear Bullant,
Sorry cause I have like wasted a lot of time first with javascript so where I was trying to build the dynamic row of the select boxes. I could not do it well that is where I switch to jquery and like you said I end of up having problem validating it. Quote:
|
| All times are GMT +1. The time now is 05:30 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.