Solved

JQuery Not Working

Posted on 2015-02-18
6
60 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to use string functions to get particular string 3 51
Building JSON/JQuery Results Display 11 52
Boolean 13 48
Add Rows on a Table 8 50
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to implement server side field validation and display customized error messages to the client.
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)

737 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