Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JavaScript Undefined Error

Posted on 2009-05-13
1
Medium Priority
?
841 Views
Last Modified: 2013-11-19
I keep getting "chkName" is undefined.
I also get error expected ")"

I have a userinfo.js file along with this.
Can someone  help me figure out why i am getting undefined errors.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
 
<!-- userinfo.html    a document for userinfo.js
        -->
 
<html xmlns = "http://www.w3.org/1999/xhtml">
   <head>
      <title> Illustrates form Input Validation </title>
      <script type = "text/javascript" src = "userinfo.js" >
      </script>
   </head>
   <body>
   <h3> Customer Information </h3>
   <form action = "">
 
   	<p>
   		<label>
   			<input type = "text" id = "custName" />
   			Name (last name, first name, middle initial)
   		</label>
   		<br /><br />
 
   		<label>
   			<input type = "text" id = "phone" />
   			Phone number (ddd-ddd-dddd)
   		</label>
   		<br /><br />
 
   		<input type = "reset" id = "reset" />
 
   		<input type = "submit" id = "submit" />
   	</p>
   </form>
 
   <!-- An inline script for the event handler registrations -->
   		<script type = "text/javascript">
   		   <!--
   // Set form element object properties to their
   // corresponding event handler functions
 
 
   		document.getElementById("custName").onchange = chkName;
   		document.getElementById("phone").onchange = chkPhone;
   // -->
 
    </script>
 
   </body>
</html>
 
 
 
// userinfo.js
// an example of input validation using the change and submit events
 
// The event handler function for the name text box
 
function chkName() {
	var myName = document.getElementById("custName");
	
	// Test the format of the input name
	// Allow the spaces after the commas to be optional
	// Allow the period after the inital to be optional
		var pos = myName.value.search(
			/^[A-Z][a-z]+, ?[A-Z][a-z]+, ?[A-Z]\.?$/);
		if (pos != 0) {
			alert("The name you entered (" + myName.value +
				") is not in the correct form. \n" +
				"The correct form is: " +
				"last-name, first-name, middle-intial \n" +
				"Please go back and fix your name");
		myName.focus();
		myName.select();
		return false;
		} else
		  return true;
	}
	
	// The event handler function for the phone number text box
	
	function chkPhone() {
		var myPhone = document.getElementById("phone");
		
		// Test the format of the input phone number
			var pos = myPhone.value.search(/^\d{3}-\d{3}-\d{4}$/);
			if (pos != 0) {
				alert("The phone number you entered (" + myPhone.value +
				") is not in the correct form. \n" +
				"The correct form is" ddd-ddd-dddd \n" +
				"Please go back and fix your phone number");
		myPhone.focus();
		myPhone.select();
		return false;
	} else
	  return true;
}

Open in new window

0
Comment
Question by:ChadAnglin
[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
1 Comment
 
LVL 15

Accepted Solution

by:
mr_egyptian earned 1000 total points
ID: 24381491
Change to the following starting on line 89  above.  You have a stray double quote.
alert("The phone number you entered (" + myPhone.value +
") is not in the correct form. \n" +
"The correct form is ddd-ddd-dddd \n" +
"Please go back and fix your phone number");

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

610 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