We help IT Professionals succeed at work.

jQuery Error

Robert Granlund
on
I'm getting an error in a validation script.  I'm using validate.js
the error:
SyntaxError: missing : after property id
item_options[association_membership]: {

I believe it is referring to the bracket...
<script>
$(document).ready(function(){
		$("#update_cart_form").validate({
errorElement: 'div',
			rules: {
				item_options[association_membership]: {
					required: true
					
				}
			},

			messages: {

				item_options[association_membership]: {
					required: "Please Choose A Membership",
					
				}

			}
		});
			
	});
</script>

<html>
<select id="association_membership" name="item_options[association_membership]" >
<option selected="" disabled="" value="">Association Membership</option>
<option value="Yes" >Yes</option>
<option  value="No" >No</option>
</select>
</html>

Open in new window


The validate js uses the name value when it looks for a field to validate.  Like I mentioned, I think it is referring to the brackets.  Is there a way to write this so the brackets are or ok or can I leave them out somehow?
Comment
Watch Question

Top Expert 2015
Commented:
Try putting the name in quotes:
$(document).ready(function(){
	$("#update_cart_form").validate({
              errorElement: 'div',
			rules: {
				"item_options[association_membership]": {
					required: true
					
				}
			},

			messages: {

				"item_options[association_membership]": {
					required: "Please Choose A Membership",
					
				}

			}
	});
			
});

Open in new window

Author

Commented:
That was it...  Thanks!