duanpiao6679 2011-11-26 17:20
浏览 19
已采纳

提交后填充单选按钮值

I try to implement the follwing code:

    <?php
    $yesno1="";
    $yesno2="";
    $option1="";
    $option2="";
    $option3="";
   if(isset($_POST['submit'])){
      $yesno1=$_POST['yesno1'];
      $yesno2=$_POST['yesno2'];
      $option1=$_POST['option1'];
      $option2=$_POST['option2'];
      $option3=$_POST['option3'];
     } 
    ?>    
   <form method="POST" name="contact_form"
  action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
 <input type="radio" name="yesno1" value="yes" style="outline:0;"/>Yes
 <input type="radio" name="yesno1" value="no" style="outline:0;"/>No
 <input type="radio" name="yesno2" value="yes" style="outline:0;"/>Yes
 <input type="radio" name="yesno2" value="no" style="outline:0;"/>No
 <input type="checkbox" name="option1" value="Milk"> Milk<br>
 <input type="checkbox" name="option2" value="Butter" checked> Butter<br>
 <input type="checkbox" name="option3" value="Cheese"> Cheese<br>
 <input type="submit" value="Submit" name='submit'>
 </form>

Once I click submit button, normally the value I seleted in radio and marked in the checkbox are gone, so how can I keep the value even after the click the submit button or refrsh the page using php, javascript is fine as well, would be better if any one can help me with it on both php and javascript since I am not very good on both of them, thanks for kind help:)

  • 写回答

2条回答 默认 最新

  • dongying7847 2011-11-26 17:25
    关注

    An example below

    <input type="checkbox" name="option1" value="Milk" <?php echo ($_POST['option1'] == 'Milk' ? 'checked' : '') ?>> Milk<br>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化