javascript - How to append new values to input -


i have search box , associated suggestion box show suggestions.

once user type in search box, suggestions appear. user able select 1 of suggestions added search input box. user able type other term receive suggestions , on.

i can show suggestions , find out suggestion has been chosen cant add selected 1 search box.

i used following codes shows alert message not change search box value.

  1. document.getelementbyid("searchform").elements[1].value = "0000";
  2. $("form#searchform:input").empty();
  3. $("input[name=term]").empty();
  4. $('#term').empty()

code

<script type="text/javascript">     function selects(value){         alert("clicked:" + value);         $('#term').empty()     } ....  <s:form id="searchform" method="post" enctype="multipart/form-data">      <s:textfield id="term" name="term" label="search" onkeyup="find(this.value)"/> </s:form> 

instead of jquery empty(), should use val() get/set value of input.

$('#term').val('');    // clears 

or, append it:

function selects (value){     alert("clicked:" + value);     var curr = $('#term').val();     if (curr)                      // delimit values nicely, if curr not empty.         curr += ", ";     $('#term').val( curr + value);  } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -