设置来自其他输入的输入值

时间:2017-04-26 05:18:32

标签: php

所以,我有这个按钮,你输入标题然后按"创建",这是一张照片: enter image description here

以下是代码:

<div class="input-group margin">
                <div class="input-group-btn">
                  <button type="button" name="artButton" data-toggle="modal" data-target="#createArticle" class="btn btn-danger">Create</button>
                </div>
                <!-- /btn-group -->
                <input type="text" class="form-control" id="artTitle" name="artTitle" placeholder="Article title">
              </div>

    </div>

我尝试用两个表单标签作为POST方法将其包围,然后使用$_POST['artTitle']来回显用户在其他输入中插入的内容,但它没有工作。

所以基本上,当你按下创建时,会出现一个模态询问有关该主题的信息,如果你在按下create ...之前在该字段中键入它,我希望标题自动填充,并且它不会。工作......

以下是我尝试将值添加到其他输入

的方法
<?php if(isset($_GET) && array_key_exists('artButton',$_GET)): ?>
                <div class="form-group">
                  <label for="createArticleTitle">Title:</label>
                  <input type="input" class="form-control" value="<?php echo $_GET['artTitle']?>" id="createArticleTitle" name="createArticleTitle" maxlength="80" placeholder="Insert Article Title...">
                </div>
                <?php endif; ?>

1 个答案:

答案 0 :(得分:1)

我认为你需要在模态中点击创建文章字段自动填充之后。只需使用像这样的onlick事件

&#13;
&#13;
$('#btnclick').click(function()
{
  // alert($('#artTitle').val());
   $('#article1').val($('#artTitle').val());

});
&#13;
<form>
<div class="input-group margin">
                <div class="input-group-btn">
                  <button type="button" name="artButton" data-toggle="modal" data-target="#createArticle" id="btnclick"class="btn btn-danger">Create</button>
                </div>
                <!-- /btn-group -->
                <input type="text" class="form-control" id="artTitle" name="artTitle" placeholder="Article title">
              </div>

    </div>
    
 </form>   
 
 <head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  
  <!-- Trigger the modal with a button -->
<!--  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> -->

  <!-- Modal -->
  <div class="modal fade" id="createArticle" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Input atricle name<input type="article" id="article1" /></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>
  
</div>

</body>
</html>
&#13;
&#13;
&#13;