doupaoyan6083 2019-05-03 10:39
浏览 117
已采纳

用于重置下拉列表中所选选项的按钮

I have a page with 2 select option dropdown lists and I can only use one of them each time I have to submit the selected option but if I use two and click on submit i get an error Only use one list and thats how it should work.

for example:

I have 2 drop lists like this one enter image description here enter image description here enter image description here

enter image description here

enter image description here enter image description here

if i choose both like the pic above and click on submit I get an error and the selected options are shown as the deffult option and thats what I want, but when I click on the reset button it need to reset them to the default value but nothing happens.

like this

enter image description here

The Options for the dropdown list is from two different arrays.

$test1 and $test2 are two different arrays

<form name="rechner" method = "POST">
<select name="one">
    <option value="" selected hidden>Choose One</option>
           <?php foreach ($test1 as $one => $value) { ?>
           <option value="<?= $value ?>" 
           <?php if ($_POST['one'] == $value) { 
                     echo 'selected="selected"';}?> ><?= $value ?>
            </option><?php
                }
            ?>
</select> 

<select name="two">
    <option value="" selected hidden>Choose one</option>
        <?php foreach ($test2 as $two => $value) { ?>
        <option value="<?= $value ?>" 
        <?php if ($_POST['two'] == $value) {
                  echo 'selected="selected"';}?> ><?= $value ?>
         </option><?php
        }
        ?>
</select> 
<input type="submit" name="calc" value="Submit" />
<input type="reset" name="reset" value="Reset">

</form>

  if ($_POST['calc'] == "Berechnen") {
    /// do something
 }


  • 写回答

1条回答 默认 最新

  • dongyan5239 2019-05-06 11:11
    关注

    found the answer on other question Here

    <script type="text/javascript">
          function resetForm($myform) {
                $myform.find('input:password, input:file, select, textarea').val('');
                $myform.find('input:radio,input:checkbox')
                            .removeAttr('checked').removeAttr('selected);
         }
    </script>
    <form name="rechner" method = "POST" id="myform">
               /////html code/////
    
    <input type="button" value="Reset" onclick="resetForm($('#myform'));">
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助