0

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

<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

3
  • You will need to use JS if you want to start searching whenever the user types in the input field. Commented May 10, 2018 at 12:51
  • No i dont want them to type. when they click the link the value between <a>value</a> should go to input field SEARCH and submit Commented May 10, 2018 at 12:53
  • 1
    You still need to use JS: it handles all the scripting that occurs on the client side. What you want is to bind a click even to the <a> element, so that it injects the correct value into your input field. Commented May 10, 2018 at 12:54

1 Answer 1

3

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

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

https://jsfiddle.net/ora0j4uu/

.submit() if you want submit it as well https://www.w3schools.com/jsref/met_form_submit.asp

edit: jquery for submit

$('.clickMe').on('click', function(){
  var value = $(this).text()
  console.log(value)
  $('input').val(value)
  $('.input-group').submit()
})
Sign up to request clarification or add additional context in comments.

1 Comment

the code is working, but when i add .submit() it does the same. nothing changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.