Solved

how to validate <select> using jQuery form validation

Posted on 2012-12-27
5
450 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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html Uncheck Checkbox 2 25
VBScript on Html 15 47
html border input line 7 16
formvalidation.io validate form on class click 4 16
This article discusses four methods for overlaying images in a container on a web page
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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…
The viewer will learn how to dynamically set the form action using jQuery.

829 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