函数未被调用或未运行

时间:2014-10-06 04:45:00

标签: javascript function

我一直在研究这个问题已经有一个星期了,并且无法弄清楚我的生活中我错过了什么,或者我是否已经将某些东西放在了不应该的地方。代码工作正常,直到我开始更改confirmSubmit()函数,现在似乎除了显示页面之外什么都没有正常工作。我让我的老师也看着它,他说他也找不到。我只是不知道也许你们中的一个人都可以帮我解决这个问题。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="AS400.css" type="text/css" />
<title>Registration</title>

<script type="text/javascript">
    /* <![CDATA[ */
    // This JavaScript removes default values form field
       function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = ""
     }
 }

// This JavaScript allows characters except numbers
 function AcceptLetters(objtextbox)
{
var exp = /[^\D]/g;
objtextbox.value = objtextbox.value.replace(exp,'');
}

// This JavaScript allows numbers only
 function AcceptDigits(objtextbox)
{
var exp = /[^\d]/g;
objtextbox.value = objtextbox.value.replace(exp,'');
}

//This JavaScript confirms everything is filled out
function confirmSubmit()
{
var submitForm = window.confirm("Are you sure you want to submit the form?");
var Special offers = false;
var offers = false;



if (document.forms[0].name.value=="Name" || document.forms[0].name.value == "") {
     window.alert("Please input your name.");
    return false;}

 if (document.forms[0].email.value == "E-Mail Address" || document.forms[0].email.value == "") {
    window.alert("Please input your email.");
    return false;}

    if (document.forms[0].password1.value == "" || document.forms[0].password2.value == "") {
    window.alert("Please input your password twice.");
    retrun false;}

if (document.forms[0].SQ.value == "" || document.forms[0].SQ.value == "none") {
    window.alert("Please choose a security question.");
    return false;}

if (document.forms[0].sq_answer.value == "Question Answer"|| document.forms[0].sq_answer.value == "") {
    window.alert("Please input a sequrity question answer.");
    return false;}

    for (var i = 0; i <= 1; ++i) {

    if (document.forms[0].SpecialOffers[i].checked ==  true) {
        Special offers = true;
        break;}
    }

    if (Special offers == false) {
        window.alert("You must select yes or no to special offers.");
        return false;
    }


    for (var k = 0; k <= 3; k++) {
    if (document.forms[0].Offers[k].checked == true) {
        offers = true;
        break;}

    }
    if (offers == false) {
        window.alert("You must choose one offer.");
        return false;}

else
 return true;
 }

/* ]] */
</script>
</head>

<body>


<form  action="FormProcessor.html"  method = "get" enctype = "application/x-www-form-urlencoded" onsubmit="return confirmSubmit()">
<table  width="50%">
<tr><th colspan="2"><h1>Registration Page</h1></th></tr>

<tr><th colspan="2"><h2>Personal Information<h2></th></tr>
<tr><th colspan="2">(Fields with asterisks are mandatory)</th></tr>
<tr><td>* Name: </td>
<td><input type="text" name="name" value="Name" maxlength="20"  onFocus="doClear(this)" onkeyup="AcceptLetters(this)" /></td></tr>
<tr><td>* E-Mail:</td>
<td><input type="text" name="email" value="E-mail Address" onFocus="doClear(this)" /> </td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><th colspan="2"><h3>Security Information</h3></th></tr>
<tr><td>* Password:</td><td><input type="password" name="password1" /></td></tr>
<tr><td>* Confirm Password:</td><td><input type="password" name="password2" /></td></tr>
<tr><td>* Security Question:</td>
<td><select id="selection" name="SQ">
<option value="none">Please Choose One</option>
<option value="color">What is your favorite color?</option>
<option value="name">What is your Mother's maiden name?</option>
<option value="pet">What is your pets name?</option>
<option value="school">What high school did you graduate from?</option>
</select></td></tr>
<tr><td>Answer:</td><td><input type="text" name="sq_answer"  value="Question Answer" onFocus="doClear(this)" /></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><th colspan="2"><h4>* Preferences</h4></th></tr>

<tr><th colspan="2">Would you like any special offers sent to your E-mail address?</th></tr>
<tr><th colspan="2">Yes<input type="radio" name="SpecialOffers" value="Yes"/>No<input type="radio" name="SpecialOffers"  value="No" /></th></tr>
<tr><th colspan="2"><h5>Interests</h5></th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Entertainment</th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Shopping</th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Business</th></tr>
<tr><th colspan="2"><input type="checkbox" name="Offers" value="check"/>Exercise</th></tr>
<tr><td></td></tr>


<tr><th colspan="2"><input id="submit" type="submit" value="Submit"/><input id="reset" type="reset" value="Reset"/></th></tr>
</table>

</form>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

您的语法错误很少:

Special offers变量不能包含空格。

关键字不是retrunreturn