?
Solved

JQuery Not Working

Posted on 2015-02-18
6
Medium Priority
?
75 Views
Last Modified: 2015-03-03
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

0
Comment
Question by:rgranlund
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40618833
hi rgranlund,

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

Can you post the markup?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40619346
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

0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40619455
Well, if you can post the markup, we can take a look.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Author Comment

by:rgranlund
ID: 40619550
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.
0
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 2000 total points
ID: 40619967
Your javascript is looking for a button I supposed called get_quote and I don't see it anywhere.

It will really help to show relevant code.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40620285
It's the script at the bottom, in the footer, not the script at he top.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 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