我已经在myform.php
具有单选组输入类型的模板上创建了表单,并且值更新为onchange="javascript:document.post.submit()"';
. 因此,每当我更改选择时,值都会随着页面刷新而更新。有什么方法可以让我在不使用 ajax 刷新页面的情况下更新我的选择?
<?php
$foods = array('pasta', 'burger', 'pizza','popcorn');
foreach ($foods as $food) {
echo '<input name="my_favorite_food" type="radio" onchange="javascript:document.post.submit()"';
$option = 'id=" ' .$food . '"';
$option = 'value="' . $food . '"';
if ($food == $my_favorite_food) $option .= 'checked="checked"';
$option .= '>';
$option .= '<label for=" '.$food .' ">' . $food .' ';
$option .= '</label>';
echo $option;
}
?>
<div id ="block">
<?php
if ($my_favorite_food == "pasta") : ?>
<h2>your favorite food is pasta</h2>
<p> my pasta recipe...... </p>
<?php endif;?>
if ($my_favorite_food == "burger") : ?>
<h2>your favorite food is burger</h2>
<p> my burger recipe...... </p>
<?php endif;?>
if ($my_favorite_food == "pizza") : ?>
<h2>your favorite food is pizza</h2>
<p> my pizza recipe...... </p>
<?php endif;?>
if ($my_favorite_food == "popcorn") : ?>
<h2>your favorite food is popcorn</h2>
<p> my popcorn recipe...... </p>
<?php endif;?>
<div>