JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2012, 06:24 AM
msmith29063 msmith29063 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 202 msmith29063 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 26 m 46 sec
Reputation Power: 10
Question JQuery Validation Plug-In: Need Help w/ Dropdowns

I'm trying to use the jQuery Validation plug-in on a form on my site. Two problems -- it doesn't seem to work and I want to use alert boxes for the errors.

Here's the code:

Code:
<script type="text/javascript">
	jQuery.validator.addMethod(
		"require_categories",
		function(value, element) {
			if (element.value == 0) {
				return false;
			} else {
				return true;
			},
			"Please select an option."
		});
	$("#publishForm").validate({
		rules: {
			category: {
				require_categories: true
			}
		}
	});
</script>

<form id="publishForm" method="post">
<select name="category[]" id="county">
<option value="">--</option>
<option value="1">County Name</option>
...
</select>
</form>


Any ideas why this isn't working? And how do I configure it to use alert boxes as opposed to inline errors?

Thank you for your help.

Reply With Quote
  #2  
Old October 16th, 2012, 03:48 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,831 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 19 h 38 m 3 sec
Reputation Power: 4192
It's probably not working because the form control's name is "category[]", not "category". Neither HTML nor JavaScript give any special treatment to form control names that include a pair of square brackets.

If you don't have a second form control with that name, remove the square brackets from it. Otherwise, try this:
Code:
	$("#publishForm").validate({
		rules: {
			'category[]': {
				require_categories: true
			}
		}
	});

Quote:
And how do I configure it to use alert boxes as opposed to inline errors?

Why would you want to do that? Many people consider using alert boxes to be less user-friendly.
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > JQuery Validation Plug-In: Need Help w/ Dropdowns

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap