Solved

JQuery Not Working

Posted on 2015-02-18
6
48 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now