Solved

JQuery Not Working

Posted on 2015-02-18
6
57 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 28

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 28

Expert Comment

by:sammySeltzer
ID: 40619455
Well, if you can post the markup, we can take a look.
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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 28

Accepted Solution

by:
sammySeltzer earned 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

685 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