-1

这是我的代码,它不起作用,没有任何警报出现,并且似乎 javascript 不起作用。任何帮助将不胜感激。

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Anyville University</title>

<script>
function nameCheck()
{
  if(input.firstName.value.length >= 2 && input.lastName.value.length >=2 &&
     input.firstName.value.match(/^[A-Za-z]+$/) && input.lastName.value.match(/     ^[A-Za-z]+$/)
   {
    return true;
   }
   else
   {
    return false;
   }
}

function emailCheck()
{
  if(input.email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{1,5})+$/)
  {
   return true;
  }
  else
  {
   return false;
  }
}

function phoneCheck()
{
  if(input.phone.value.length == 10 && input.phone.value.match(/^[0-9]+$/))
   {
    return true;
   }
  else
  {
   return false;
  }
}

function ValidateForm()
{
  if(nameCheck == false)
  {
   alert("Invalid first or last name");
   input.firstName.focus();
  }

  if(emailCheck == false)
  {
   alert("Invalid email address");
   input.email.focus();
  }

  if(phoneCheck == false)
  {
   alert("Invalid phone number");
   input.phone.focus();
  }
}

</script>



</head>
<body>
<h1><b>Anyville University Feedback</b></h1>

<form name="input" action="/~mkamal/csc442/cgi-bin/thanks.cgi" method="get"
onsubmit="return ValidateForm();">
First Name: <input type="text" name="firstName" size="15" maxlength="20"><br>
Last Name: <input type="text" name="lastName" size="15" maxlength="20"><br>
Postal Address: <input type="text" name="postal" size="60" maxlength="60"><br>
E-Mail Address: <input type="text" name="email" size="25" maxlength="30"><br>
Telephone Number: <input type="text" name="phone" size="3" maxlength="3">-
                  <input type="text" name="phone" size="3" maxlength="3">-
                  <input type="text" name="phone" size="4" maxlength="4"><br>

<p>Which day did you visit campus?</p>
<select name="days">
<option value="Sunday" selected>Sunday</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
</select>

<br>

<p>Select what you liked about campus: </p>
<input type="checkbox" name="like" value="students">Students<br>
<input type="checkbox" name="like" value="location">Location<br>
<input type="checkbox" name="like" value="campus">Campus<br>
<input type="checkbox" name="like" value="atmosphere">Atmosphere<br>
<input type="checkbox" name="like" value="dorm">Dorm Rooms<br>
<input type="checkbox" name="like" value="sports">Sports<br>

<p>How did you become interested in the University?</p>
<input type="radio" name="interest" value="parents">Parents<br>
<input type="radio" name="interest" value="friends">Friends<br>
<input type="radio" name="interest" value="tv">Television<br>
<input type="radio" name="interest" value="internet">Internet<br>
<input type="radio" name="interest" value="other">Other<br>

<textarea rows="5" cols="50">
Enter additional comments here.
</textarea>

<input type="submit" value="Submit">
<input type="reset" value="Reset">

</form>
</body>
</html>

我认为这可能与脚本有关,但我不确定。

4

1 回答 1

1

在第 11 行,您错过了一个).

if(input.firstName.value.length >= 2 && input.lastName.value.length >=2 &&
     input.firstName.value.match(/^[A-Za-z]+$/) && input.lastName.value.match(/     ^[A-Za-z]+$/) )  // <----- HERE

在第 22 行,你也错过了)

在功能ValidateForm

function ValidateForm()
{
  if(nameCheck() == false)
  {
   alert("Invalid first or last name");
   input.firstName.focus();
  }

  if(emailCheck() == false)
  {
   alert("Invalid email address");
   input.email.focus();
  }

  if(phoneCheck() == false)
  {
   alert("Invalid phone number");
   input.phone.focus();
  }
}
于 2013-11-07T03:13:23.187 回答