duandian2725 2017-06-08 14:50
浏览 61
已采纳

使用html时,我可以将用户的输入添加到onclick =“return confirm”吗?

Is it possible to add something a user wrote or selected to a confirm window (onclick="return confirm) before its sent to a script to process? If possible only with php and html.

     <form action="store.php" method="POST">
  <select name="day">
    <option value="" disabled selected>Tag</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
  <select name="month">
    <option value="" disabled selected>Monat</option>
    <option value="Januar">Januar</option>
    <option value="Febraur">Febraur</option>
    <option value="März">März</option>
  </select>
  <select name="year">
    <?php
      $year = date("Y");
      $nextyear = $year + 1;
      $month = date("n");
      if ($month >= 8) {
        echo "<option value='' disabled selected>Jahr</option><option value=".$year.">".$year."</option><option value=".$nextyear.">".$snextyear."</option>";
      }else {
        echo "<option value=".$syear.">".$syear."</option>";
      }
     ?>
  </select>
  <input type="text" name="exam" placeholder="Prüfung"/>
  <input type="submit" onclick="return confirm('Are you sure?')"/>
</form>
  • 写回答

1条回答 默认 最新

  • dongpan5289 2017-06-08 14:56
    关注

    So read the value of the input[s] and put it in the string.

    function confirmSubmit() {
       var form = document.forms[0],  //reference the form
           year = form.year.value,    //get the input values
           exam = form.exam.value;
       return confirm("your string " + year + " " + exam);  //string concatenation
    }
         <form action="" method="POST">
      <select name="day">
        <option value="" disabled selected>Tag</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
      </select>
      <select name="month">
        <option value="" disabled selected>Monat</option>
        <option value="Januar">Januar</option>
        <option value="Febraur">Febraur</option>
        <option value="März">März</option>
      </select>
      <select name="year">
        <option>1</option>
        <option>2</option>
        <option>3</option>
      </select>
      <input type="text" name="exam" placeholder="Prüfung"/>
      <input type="submit" onclick="return confirmSubmit()"/>
    </form>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection