Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

JQuery Not Working

I have a website that uses Expression Engine as the CMS.
I have a few fields that need validating before a form does its thing.

I used the Validate.js

The code is not working.  It was but is not now and I'm not sure why.
<script>
 $(function() {
		$.validator.addMethod(
			"regex",
			function(value, element, regexp) {
				var re = new RegExp(regexp);
				return this.optional(element) || re.test(value);
			},
			"Incorrect format; Please check your input.");
	});

$.noConflict();
$( document ).ready(function(){
		$("#get_quote").validate({
errorElement: 'div',
			rules: {
				bike_value: {
					required: true,
					digits: true
				},
				bike_state: {
					required: true,
					maxlength: 2
				},
				email_value: {
					required: true,
					email: true,
					regex: "^((\"[\\w\\s-]+\")|([\\w-]+(?:\\.[\\w-]+)*)|(\"[\\w\\s-]+\")([\\w-]+(?:\\.[\\w-]+)*))(@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-zA-Z]{2,6}(?:\\.[a-zA-Z]{2})?)$)|(@\\[?((25[0-5]\\.|2[0-4][0-9]\\.|1[0-9]{2}\\.|[0-9]{1,2}\\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\]?$)"

				}
			},

			messages: {

				bike_value: {
					required: "Please enter the bike value"
				},
				bike_state: {
					required: "Please choose your state"
				},
				email_value: {
					 required: "Please enter an email address",
					 email: "Please enter a valid email address",
					 regex: "Please enter this particular format of email address"
				}		

			},
			submitHandler: function(form) {
			form.submit();
			}


		});
	});

</script>

Open in new window

Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

hi rgranlund,

 When you say "not working", what do  you mean?

Can you post the markup?
Avatar of Robert Granlund

ASKER

I have learned that the jQuery Validate plugin is looking for the name attribute of the input field.  My name field has brackets.  This is causing the jQuery not to work.  I'm not sure how to fix this problem:
<script>
$(document).ready(function(){


		$("#update_cart_form").validate({
		
errorElement: 'div',
			rules: {
				item_options[accessories_value]: {
					required: true,
					digits: true
				}
			},

			messages: {

				purchase_price: {
					required: "Please enter the bike value",
					digits: "Please enter only numeric values"
				}

			}
		});
			
	});

</script>

Open in new window

Well, if you can post the markup, we can take a look.
http://23.101.151.179/index.php?/store/29
the Script is included in the footer.  The field I am trying to validate is the Value of Attached accessories.
ASKER CERTIFIED SOLUTION
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's the script at the bottom, in the footer, not the script at he top.