?
Solved

how to validate <select> using jQuery form validation

Posted on 2012-12-27
5
Medium Priority
?
462 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 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

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.
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…
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.…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Suggested Courses

800 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