2016-12-17 24 views
0

這裏是我的index.html代碼: -我想打一個狗計算器,它顯示比例

 <!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>Untitled Document</title> 
 
</head> 
 

 
<body> 
 
<h1>Dog Love Calculator</h1> 
 
<form action="dog2.php" method="post" name="DogCal" onsubmit="return validateForm()" > 
 

 
<h3>Do Your Dog Hugs you with Eyes?</h3> 
 

 
<strong><input name="hugs" type="radio" value="hugs_1" /> 
 
Yes</strong><br> 
 
<input name="hugs" type="radio" value="hugs_2" /> 
 
<strong>No</strong><br> 
 
<input name="hugs" type="radio" value="hugs_3" /> 
 
<strong>Maybe</strong><br> <br> 
 

 
<h3>Does Your Dog Lifts his Eyebrows when Meets You?</h3> 
 
<input name="eyebrows" type="radio" value="eyebrows_1" /> 
 
<strong>Yes, Left One</strong><br /> 
 
<input name="eyebrows" type="radio" value="eyebrows_2" /> 
 
<strong>No, Right One</strong><br /> 
 
<input name="eyebrows" type="radio" value="eyebrows_3" /> 
 
<strong>No</strong><br /><br> 
 

 
<h3>What Signs does He show when you Leave Home?</h3> 
 
<input name="signs" type="radio" value="signs_1" /> 
 
<strong>Panic</strong><br /> 
 
<input name="signs" type="radio" value="signs_2" /> 
 
<strong>Calmness</strong><br /><br> 
 

 
<h3>Where does he like to sleep?</h3> 
 

 
<strong><input name="sleep" type="radio" value="sleep_1" /> 
 
On His Bed</strong><br> 
 
<input name="sleep" type="radio" value="sleep_2" /> 
 
<strong>Beside you or on your bed</strong><br><br> 
 

 
<h3>Does he Give you His favorite toy?</h3> 
 
<input name="toy" type="radio" value="toy_1" /> 
 
<strong>Yes</strong><br /> 
 
<input name="toy" type="radio" value="toy_2" /> 
 
<strong>No</strong><br /> 
 
<input name="toy" type="radio" value="toy_3" /> 
 
<strong>Sometimes</strong><br /><br> 
 

 
<h3>Does he take Interest in what you are doing?</h3> 
 
<input name="interest" type="radio" value="interest_1" /> 
 
<strong>Yes</strong><br /> 
 
<input name="interest" type="radio" value="interest_2" /> 
 
<strong>No</strong><br /><br> 
 

 
<h3>When you call your dog, does your pup quickly Returns Your Call?</h3> 
 
<input name="call" type="radio" value="call_1" /> 
 
<strong>Yes</strong><br /> 
 
<input name="call" type="radio" value="call_2" /> 
 
<strong>No</strong><br /><br> 
 

 
<h3>How Your Dog wags his tail in front of you?</h3> 
 
<input name="tail" type="radio" value="tail_1" /> 
 
<strong>To the Right</strong><br /> 
 
<input name="tail" type="radio" value="tail_2" /> 
 
<strong>To the Left</strong><br /><br> 
 

 
<h3>Does he Yawn With You?</h3> 
 
<input name="yawn" type="radio" value="yawn_1" /> 
 
<strong>Yes</strong><br /> 
 
<input name="yawn" type="radio" value="yawn_2" /> 
 
<strong>No</strong><br /> 
 
<input name="yawn" type="radio" value="yawn_3" /> 
 
<strong>Sometimes</strong><br /><br> 
 

 
<h3>How your Dog Move his ears in Front of You? </h3> 
 
<input name="ear" type="radio" value="ear_1" /> 
 
<strong>Shift The Left Ear</strong><br /> 
 
<input name="ear" type="radio" value="ear_2" /> 
 
<strong>Shift The Right Ear</strong><br /><br> 
 

 
<input type="submit" name="SubmitButton" value="Submit" > 
 

 
<input type="reset" value="Reset"> 
 
</form> 
 
</body> 
 
</html>

Dog2.php是行動的文件。

我希望每個yes都有10%,每個no需要3%,每個可能,有時需要5%,最後主回聲將會是他們結果的總和。

如果有人選擇:是的,是的,不,是的,有時。

那麼結果將是這樣的:10 + 10 + 3 + 10 + 5 = 38

和回聲會像

你的狗愛你38%..這個樣子。

+0

有這麼多的話要說...... 1.使用HTML5。 2.請縮進。 3. SO不是代碼提供工具,我們在遇到錯誤時提供幫助。這個問題太廣泛了。 3.「我想要一個狗計算器」 - >太好了,我們爲你感到高興。那裏沒有問題。 4.歡迎來到SO! – nicovank

回答

1

我犯了一個快速測試。這對我有用。你可以複製並使用它。

dog.html

 <!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>Untitled Document</title> 
</head> 

<body> 
<h1>Dog Love Calculator</h1> 
<form action="dog2.php" method="post" name="DogCal" onsubmit="return validateForm()" > 

<h3>Do Your Dog Hugs you with Eyes?</h3> 

<strong><input name="hugs" type="radio" value="10" />Yes</strong><br> 
<input name="hugs" type="radio" value="3" /><strong>No</strong><br> 
<input name="hugs" type="radio" value="5" /><strong>Maybe</strong><br> <br> 

<h3>Does Your Dog Lifts his Eyebrows when Meets You?</h3> 
<input name="eyebrows" type="radio" value="10" /><strong>Yes, Left One</strong><br /> 
<input name="eyebrows" type="radio" value="3" /><strong>No, Right One</strong><br /> 
<input name="eyebrows" type="radio" value="5" /><strong>No</strong><br /><br> 

<h3>What Signs does He show when you Leave Home?</h3> 
<input name="signs" type="radio" value="10" /><strong>Panic</strong><br /> 
<input name="signs" type="radio" value="5" /><strong>Calmness</strong><br /><br> 

<h3>Where does he like to sleep?</h3> 

<input name="sleep" type="radio" value="10" /><strong>On His Bed</strong><br> 
<input name="sleep" type="radio" value="5" /><strong>Beside you or on your bed</strong><br><br> 

<h3>Does he Give you His favorite toy?</h3> 
<input name="toy" type="radio" value="10" /><strong>Yes</strong><br /> 
<input name="toy" type="radio" value="3" /><strong>No</strong><br /> 
<input name="toy" type="radio" value="5" /><strong>Sometimes</strong><br /><br> 

<h3>Does he take Interest in what you are doing?</h3> 
<input name="interest" type="radio" value="10" /><strong>Yes</strong><br /> 
<input name="interest" type="radio" value="3" /><strong>No</strong><br /><br> 

<h3>When you call your dog, does your pup quickly Returns Your Call?</h3> 
<input name="call" type="radio" value="10" /><strong>Yes</strong><br /> 
<input name="call" type="radio" value="3" /><strong>No</strong><br /><br> 

<h3>How Your Dog wags his tail in front of you?</h3> 
<input name="tail" type="radio" value="10" /><strong>To the Right</strong><br /> 
<input name="tail" type="radio" value="3" />a<strong>To the Left</strong><br /><br> 

<h3>Does he Yawn With You?</h3> 
<input name="yawn" type="radio" value="10" /><strong>Yes</strong><br /> 
<input name="yawn" type="radio" value="3" /><strong>No</strong><br /> 
<input name="yawn" type="radio" value="5" /><strong>Sometimes</strong><br /><br> 

<h3>How your Dog Move his ears in Front of You? </h3> 
<input name="ear" type="radio" value="10" /><strong>Shift The Left Ear</strong><br /> 
<input name="ear" type="radio" value="3" /><strong>Shift The Right Ear</strong><br /><br> 

<input type="submit" name="SubmitButton" value="Submit" > 

<input type="reset" value="Reset"> 
</form> 
</body> 
</html> 

dog2.php

<?php 
$hugs = $_POST['hugs']; 
$eyebrows = $_POST['eyebrows']; 
$signs = $_POST['signs']; 
$sleep = $_POST['sleep']; 
$toy = $_POST['toy']; 
$interest = $_POST['interest']; 
$call = $_POST['call']; 
$tail = $_POST['tail']; 
$yawn = $_POST['yawn']; 
$ear = $_POST['ear']; 

echo 'hugs: '.$hugs.'<br>'; 
echo 'eyebrows: '.$eyebrows.'<br>'; 
echo 'signs: '.$signs.'<br>'; 
echo 'sleep: '.$sleep.'<br>'; 
echo 'toy: '.$toy.'<br>'; 
echo 'interest: '.$interest.'<br>'; 
echo 'call: '.$call.'<br>'; 
echo 'tail: '.$tail.'<br>'; 
echo 'yawn: '.$yawn.'<br>'; 
echo 'ear: '.$ear.'<br>'; 

echo 'total: '.($hugs+$eyebrows+$signs+$sleep+$toy+$interest+$call+$tail+$yawn+$ear); 
?> 

希望這有助於。

+0

謝謝...這就是我想...一個更多的幫助..我已經把所有這些文件表..現在,當我點擊提交按鈕它的作品像下載按鈕.. –

+0

請顯示您的代碼 – bugscoder

+0

其完成..謝謝..實際上我使用它沒有服務器.. –

1

讓您的生活變得輕鬆,您只需將%作爲值放入您的單選按鈕中。 例如:

<input name="yawn" type="radio" value="10" /> <strong>Yes</strong><br /> 
<input name="yawn" type="radio" value="3" /><strong>No</strong><br /> 
<input name="yawn" type="radio" value="5" /><strong>Sometimes</strong><br /> 

,你可以做計算在dog2.php

+0

嘗試過,但如何計算哪個選項被點擊..? 我試過這個 $ hugs = $ _POST [「hugs」]; $ eyebrows = $ _POST [「eyebrows」]; $ signs = $ _POST [「signs」]; $ sleep = $ _POST [「sleep」]; $ toy = $ _POST [「toy」]; $ interest = $ _POST [「interest」]; $ call = $ _POST [「call」]; $ tail = $ _POST [「tail」]; $ yawn = $ _POST [「打哈欠」]; $ ear = $ _POST [「ear」]; $ total = $ hugs + $ eyebrows + $ signs + $ sleep + $ toy + $ interest + $ call + $ tail + $ yawn + $ ear; –

+0

我認爲你的php是正確的。 – bugscoder

+0

但它不工作..它只有第一個選項..如果我們選擇任何其他選項輸出是一個空白頁 –