php实例:响应checkbox复选框中的值

发布时间:2020-08-12编辑:脚本学堂
本文介绍下,又一个php的例子,通过一个演示实例来学习如何响应checkbox复选框,有需要的朋友参考下。

php代码实现的一个复选框操作的例子。

代码:

<html>
<head>
<title>Checkbox复选框演示示例--www.jb200.com</title>
</head>
<body>
<h1>Checkbox复选框的Demo</h1>

<h3>演示复选框</h3>
<form action ="HandleFormCheckBox.php">

<ul>
  <li><input type ="checkbox" name ="chkFries" value ="11.00">Fries</li>
  <li><input type ="checkbox" name ="chkSoda"  value ="12.85">Soda</li>
  <li><input type ="checkbox" name ="chkShake" value ="1.30">Shake</li>
  <li><input type ="checkbox" name ="chkKetchup" value =".05">Ketchup</li>
</ul>
<input type ="submit">
</form>

</body>
</html>
<!-- HandleFormCheckBox.php
<html>
<head>
<title>Checkbox Demo</title>
</head>
<body>
<h3>演示阅读复选框</h3>
<?
print <<<HERE
chkFries: $chkFries <br>
chkSoda: $chkSoda <br>
chkShake: $chkShake <br>
chkKetchup: $chkKetchup <br>
<hr>

HERE;

$total = 0;

if (!empty($chkFries)){
  print ("你选择了 Fires <br>");
  $total = $total + $chkFries;
}

if (!empty($chkSoda)){
  print (你选择了 Soda" <br>");
  $total = $total + $chkSoda;
}

if (!empty($chkShake)){
  print ("你选择了 Shake <br>");
  $total = $total + $chkShake;
}

if (!empty($chkKetchup)){
  print ("你选择了 Ketchup <br>");
  $total = $total + $chkKetchup;
}

print "总计花费:$$total";

?>
</body>
</html>
-->