dongxian0320 2018-06-18 14:59
浏览 89
已采纳

使用模式将单选按钮的值传递给文本框

Is it possible to pass the selected radio button value to textbox in one page using modal ? im trying to make an attendance form for library, that the students will click the select purpose button and modal will appear they will choose either assignment or reading , after they select and click the confirm button the selected radio button will appear in the textbox. hope you can help me with this one. advance thanks.

heres my sample code:

 <html>
    <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<form class="inputForm" >
<div class="inputbox">
<input type="text"  required/>
<label>Purpose</label>
</div>

<input type="submit" value="Select Purpose" class="button1" data-toggle="modal" data-target="#exampleModal">

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Purpose:</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
         <div class="custom-control custom-radio">
       <input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
       <label class="custom-control-label" for="customRadio1">Assignment</label>
     </div>
     <div class="custom-control custom-radio">
      <input type="radio" id="customRadio2" name="customRadio" class="custom-control-input">
      <label class="custom-control-label" for="customRadio2">Reading</label>
     </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-primary">Confirm</button>
     </div>
    </div>
    </div>
    </div>
     </form>
    </body>
    </html>
  • 写回答

1条回答 默认 最新

  • douciwang6819 2018-06-18 17:51
    关注

    It's more like a client side (JavaScript) thing to me. Live example

    1. Include the following in your HTML:

    <script>
    
        $('#modal_button').click(function() {
    
            var value = $("input:radio:checked").next().text();
            $('#purpose_input').val(value);
            $('#exampleModal').modal('hide');
        });
    
    </script>
    

    Add id="modal_button" to your confirm button.

    2. Change the form to:

    <form class="inputForm" >
        <div class="inputbox">
            <input id="purpose_input" type="text"  required/>
            <label>Purpose</label>
        </div>
    </form>
    

    3. Change the submit button to:

    <button class="button1" data-toggle="modal" data-target="#exampleModal">Select Purpose</button>
    

    I hope it helps!

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

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题