Solved

how to validate <select> using jQuery form validation

Posted on 2012-12-27
5
445 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks! It was something very simple that i overlooked. I appreciate your help!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Radio button Onclick submit form with validation 5 23
Help with HTML 7 38
HTML button disabled 11 36
SVG Logo 4 18
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now