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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?