Type=Radio應用範例<?php $command=$_POST["command"]; if ($command==null) { echo("<html> <body> <center> <form method=post action=$SELF_PHP> <p> 數目一 <input type=text name=num1 size=5> <input type=radio name=choice value='+'>+ <input type=radio name=choice value='-'>- <input type=radio name=choice value='*'>* <input type=radio name=choice value='/'>/ 數目二 <input type=text name=num2 size=5><p> <input type=submit name=command value=送出> <input type=reset name=command value=清除> </form> </center> </body> </html>"); } if ($command=="送出") { $num1=$_POST["num1"]; $choice=$_POST["choice"]; $num2=$_POST["num2"]; switch ($choice) { case "+" : $result=$num1+$num2; $plus ="checked"; break; case "-" : $result=$num1-$num2; $minus="checked"; break; case "*" : $result=$num1*$num2; $times="checked"; break; case "/" : $result=$num1/$num2; $div ="checked"; break; } echo("<html> <body> <center> 結果=$result </center> </body> </html>"); } ?> |