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.
document.getelementbyid("searchform").elements[1].value = "0000";
$("form#searchform:input").empty();
$("input[name=term]").empty();
$('#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
Post a Comment