javascript - jquery autocomplete with hidden data cant get id and value -
i using jquery.autocomplete.js. can term , output sent using json encode, can't value in 1 textbox , id in hidden textbox.
script:
<script type="text/javascript"> $().ready(function() { $(".autocomplete_user").autocomplete("/get_user_name", { minchars: 0, max: 12, autofill: true, mustmatch: true, matchcontains: false, scrollheight: 220, formatitem: function(row, i, total) { return row.value; }, formatresult: function(row) { return row.value; } }); $('.autocomplete_user').result(function(event, data, formatted) { $('#user_id_val').val(!data ? '' : data.id); });});
- view:
<input type="text" class="form-control input-md autocomplete_user" name="receiver_name" value="" placeholder=" type here"> <input type="hidden" name="receiver_id" id="user_id_val" value="" /> i can output this
[{id: "131", value: "murugan"}]
Comments
Post a Comment