简体   繁体   English

如何动态提交输入字段的值

[英]How submit value of input field dynamically

I have some categories: 我有一些类别:

<div class="cbp-l-inline-title" style=" font-size: 18px;">
    <span style="color: #0669b4">Generic Name:</span> 
    <a><?php echo $category[0]['generic_name'];?></a>
</div>

and I want on click to insert value of this <a> to this form 我想单击以将此<a>值插入此表单

<form method="post" action="/search/index" class="input-group" style="width: 45%; margin-left: 646px">
    <input type="text" name="search" id="search" class="form-control" minlength=3 placeholder="Generic" aria-label="Recipient's username" aria-describedby="basic-addon2">
    <div id="suggesstion"></div>
    <div class="input-group-btn input-group-append">
        <button class="btn btn-primary btn-outline-secondary" type="submit" name="submit">Search</button>
    </div>
</form>

so that it dynamically starts search of results of this string. 以便它动态地开始搜索此字符串的结果。 I can't send this value to url because it is not latin characters 我无法将此值发送到url,因为它不是拉丁字符

html html

<div class="cbp-l-inline-title" style=" font-size: 18px;">
  <span style="color: #0669b4">Generic Name:</span> 
  <p class="clickMe">click me: text to send after click</p>
</div>

<form method="post"  class="input-group">
  <input type="text" name="search" id="search" class="form-control" minlength=3
                       placeholder="Generic" aria-label="Recipient's username"
                       aria-describedby="basic-addon2">
  <div id="suggesstion"></div>
  <div class="input-group-btn input-group-append">
     <button class="btn btn-primary btn-outline-secondary" type="submit" name="submit">Search</button>
  </div>
</form>

And javascript in jquery 和jQuery中的JavaScript

$('.clickMe').on('click', function(){
  var value = $(this).text()
  $('input#search').val(value)
})

https://jsfiddle.net/ora0j4uu/ https://jsfiddle.net/ora0j4uu/

.submit() if you want submit it as well https://www.w3schools.com/jsref/met_form_submit.asp .submit()(如果您也想提交) https://www.w3schools.com/jsref/met_form_submit.asp

edit: jquery for submit 编辑: jQuery提交

$('.clickMe').on('click', function(){
  var value = $(this).text()
  console.log(value)
  $('input').val(value)
  $('.input-group').submit()
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM