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

JavaScript Undefined Error

Posted on 2009-05-13
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"?>
<!-- userinfo.html    a document for userinfo.js
<html xmlns = "http://www.w3.org/1999/xhtml">
      <title> Illustrates form Input Validation </title>
      <script type = "text/javascript" src = "userinfo.js" >
   <h3> Customer Information </h3>
   <form action = "">
   			<input type = "text" id = "custName" />
   			Name (last name, first name, middle initial)
   		<br /><br />
   			<input type = "text" id = "phone" />
   			Phone number (ddd-ddd-dddd)
   		<br /><br />
   		<input type = "reset" id = "reset" />
   		<input type = "submit" id = "submit" />
   <!-- 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;
   // -->
// 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");
		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");
		return false;
	} else
	  return true;

Open in new window

Question by:ChadAnglin
1 Comment
LVL 15

Accepted Solution

mr_egyptian earned 250 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


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Increase the size of the modal in Bootstrap 5 43
Javascript_Set_dropdown_value 7 40
parse url to form? 7 25
Selected in an option list 13 19
This article discusses how to create an extensible mechanism for linked drop downs.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

809 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