Kevin C Kevin C - 5 months ago 18
Javascript Question

Javascript Search Issue manual Keypress

In example below, I`m copying select list option from one field to another (From id "email" to "Mail") . So if I select "Account", it will get added to text search field. This issue is with the "Search" field. Even though the value is getting copy/pasted in text search box, search is not showing any results until I manually press any key in that search box. Can someone please suggest how can I fix this issue?

I`m using filterz search model for this project which populates search results on every key pressed - http://yiotis.net/filterizr/



$(function() {
$("#email").change(function() {
$('#mail').val(this.value);
});
});

<form id="form1">
<select id="email" name="a" size="5" style="width: 400px;">
<option value="Account">Account</option>
<option value="Outlook">Outlook</option>
<option value="Mobile">Mobile</option>

</select>
</form>
<form id="form2">
<input name="text" type="text" data-search="data-search" id="mail" />

</form>




Answer

You need to manually trigger keyup event like below:

$(function() {
  $("#email").change(function() {
    $('#mail').val(this.value).trigger("keyup"); // manually trigger keyup event

  });
});
<form id="form1">
  <select id="email" name="a" size="5" style="width: 400px;">
    <option value="Account">Account</option>
    <option value="Outlook">Outlook</option>
    <option value="Mobile">Mobile</option>

  </select>
</form>
<form id="form2">
  <input name="text" type="text" data-search="data-search" id="mail" />

</form>

Comments