Solved

how to validate <select> using jQuery form validation

Posted on 2012-12-27
5
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

733 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