2012-11-23 58 views
0

我想創建一個小調查/問卷,詢問用戶是否大於18歲。一旦他們按下Enter按鈕,我想提出兩個選擇。一:如果他們不超過18歲,它會帶他們到另一個網頁。還有兩點:如果他們超過18歲,將會把他們帶到另一個網頁。 這讓我想起Java中的「if」「else」語句,但我知道這不是Java。我正在使用HTML(Dreamweaver),我無法弄清楚。有人能指出我正確的方向嗎?如何讓年齡限制的網站將人員帶到另一個網站,如果年齡好?

我已經得到了它的基本框架:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>WAIT!</title> 
</head> 

<body> 
<p>WAIT!</p> 
<p>Let us know more about you.</p> 
<p>Please fill out this form so that we can guide you to YOUR world. </p> 
<p>&nbsp;</p> 
<p>Are you a:</p> 
<form> 
<input type="radio" name="sex" value="male">Male<br> 
<input type="radio" name="sex" value="female">Female 
</form> 
<p> Age: </p> 
<form> 
<input type="radio" name="sex" value="male"> 
younger than 18<br> 
<input type="radio" name="sex" value="female"> 
18+ 
</form> 
<p></p> 
<form name="input" action="#" method="get"> 
<input type="submit" value="Enter"> 
</form> 
</body> 
</html> 

要查看輸出,複製和粘貼上面的代碼並輸入here。然後按提交代碼。

+1

您正在運行_any_可編程服務器嗎?什麼是處理表單提交? –

+0

@MattBall我不這麼認爲,因爲在這種情況下問題將被標記。由於這被標記爲Dreamweaver,並且您可以公平地假設問題poser的技能。 – defau1t

回答

1

這裏是將用戶重定向上使用javascript檢查什麼是無線電選擇的示例腳本:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>WAIT!</title> 
</head> 
<script> 
function redirect() { 
    if(document.getElementById("m").checked == true) 
    { 
     window.open("http://www.codeforbrowser.com") 
    } 
    else { 
     window.open("http://www.yahoo.com") 
    } 

} 
</script> 
<body> 
<p>WAIT!</p> 
<p>Let us know more about you.</p> 
<p>Please fill out this form so that we can guide you to YOUR world. </p> 
<p>&nbsp;</p> 
<p>Are you a:</p> 
<form> 
<input type="radio" name="sex" value="male">Male<br> 
<input type="radio" name="sex" value="female">Female 
</form> 
<p> Age: </p> 
<form> 
<input type="radio" name="sex" value="male" id="m" > 
younger than 18<br> 
<input type="radio" name="sex" value="female" id="f"> 
18+ 
</form> 
<p></p> 
<form name="input" action="#" method="get"> 
<input type="submit" value="Enter" onclick="redirect();"> 
</form> 
</body> 
</html> 

DEMO

+0

它工作!謝謝defau1t! – user1753668

+0

@ user1753668:在這種情況下,您可能想要接受答案。 – defau1t

-1

賦予表單一定的ID;

<form id="sex_form"> 
<input type="radio" name="sex" value="male"> 
younger than 18<br> 
<input type="radio" name="sex" value="female"> 
18+ 
</form> 
<input type="submit" onclick="validate()" value="Enter"> 

    <script type="text/javascript"> 
     function validate(){ 
      var form = document.getElementById('sex_form'); 
      if(form.firstElementChild.checked){ 
      alert('to younger'); 
          //window.open('younger'); 
      } 
      else if(form.firstElementChild.nextElementSibling.nextElementSibling.checked){ 
          //window.open('older'); 
      alert('to 18+'); 
      } 
      else 
      alert('none selected'); 
     } 


    </script> 
+0

這不是我一直在尋找的東西,但感謝您的輸入/幫助! – user1753668