2014-10-06 105 views
-4

我一直在为此工作了一个星期,无法弄清楚我错过了什么,或者如果我把某些东西放在了它不应该存在的地方。代码工作正常,直到我开始更改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

您是否尝试过使用Firebug或Chrome开发工具调试代码?如果你的页面没有显示内容或工作不正常,你的脚本中可能会出现错误,调试它将揭示罪魁祸首。 Chrome试图使用您的网页时出现很多控制台错误。 – Krease 2014-10-06 04:47:44

+0

它正在正确显示内容。它并没有使用这些功能。 – Phibermatrix 2014-10-06 04:50:04

+1

这不是我们在这里做的。我们不会收集全部非工作代码,也不会收集有关您调试它的所有信息,并且神奇地解决您的所有问题。这不是StackOverflow的工作原理。如果您正在解决问题,并且您有一个具体问题可以提供详细信息,那么您可能会得到一些帮助。首先要开始查看调试控制台中报告的错误并从那里开始。 – jfriend00 2014-10-06 04:50:57

回答

0

你有几个语法错误:

Special offers变量不能在它的空间。

关键字不是retrunreturn

+1

请帮助教导OP如何为自己查看这些错误,而不是将我们用作语法检查器。 – jfriend00 2014-10-06 04:54:26

+0

我修正了语法错误,它仍然在做着同样的事情,它仍然在提交表单时没有进行错误检查。另外,当我点击框的框应该被清除的默认文本,但是这不是 – Phibermatrix 2014-10-06 04:54:53

+0

是啊我发现返回错误,并修复语法错误,并得到它的一切工作,我真的很感谢帮助。 – Phibermatrix 2014-10-06 05:01:28