Solved

how to validate <select> using jQuery form validation

Posted on 2012-12-27
5
448 Views
Last Modified: 2012-12-28
Hi,
I'm using the jQuery validation (http://docs.jquery.com/Plugins/Validation) for my form. It works great for <input> fields and <textarea> fields. However, it doesn't show an error message for my two <select> dropdowns. I've read alot of discussion about this but with little solutions or answers.
Does anyone have a good rule or solution to use for forms with <select> dropdowns?

I've attached my code.
In my code, the part that I'm asking for help with a rule, relates to this code:
The jQuery validation rule:
<script type="text/javascript" charset="utf-8">
      $(document).ready(function(){
      $("#apForm").validate({
            rules: {
                                            
            }});
      });
</script>


Thanks!
form-page.html
0
Comment
Question by:ron4721
  • 2
  • 2
5 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38724326
What is it you think you need to validate on a select.  The values are all predefined in the HTML, and if you do not have a default pre-selected, then you have a design flaw.

Cd&
0
 

Author Comment

by:ron4721
ID: 38724342
I need to validate that the user has chosen one of the items on the select. For example, on my state/province/territory select, the user needs to pick one in the list. The same goes for the country select. How would you recommend I fix the HTML to have a default pre-selected?
0
 
LVL 13

Accepted Solution

by:
haloexpertsexchange earned 500 total points
ID: 38724364
This is how you define a default select value.
http://stackoverflow.com/questions/3518002/how-to-set-default-value-for-html-select-element
What you do is  
Set selected for the option you want to be the default.

<option selected>
3
</option>
According to the HTML 4 or HTML5 standard, selected is a Boolean Attribute which means that its presence means "true", and it's absence means "false", and it can only take 3 value: none, empty string "", or itself, eg.

<option selected="">
3
</option>

<option selected="selected">
3
</option>
0
 
LVL 13

Expert Comment

by:haloexpertsexchange
ID: 38724372
By default otherwise the first option is always selected.
What you can do once you choose a default is to check to see which value is selected and if the value is still the default then you should know that nothing has been changed and validate it that way.
0
 

Author Closing Comment

by:ron4721
ID: 38727203
Thanks! It was something very simple that i overlooked. I appreciate your help!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question