0

I want auto complete text box with text and id .I used the following code for auto complete in my application

<script type="text/javascript">
var $auto=$.noConflict();
$auto(document).ready(function(){    
    var data3 = ['niju','vivek','anil','Anil'];
    $auto("#employee").autocomplete(data3);

  });
</script>

<input   type="text" name="employee" id="employee" value="" class="inp-form"> 

In this code we faced one drawback .There can be duplicate entry is possible since the same values as been repeated .

How to get id value instead of text label ?

Any suggestions are highly appreciated.

Demo Here

1

1 Answer 1

1

You can try with a source define like : [ { label: "Choice1", value: "value1" }, ... ].
See documentation here : autocomplete#option-source

In your case it would be something like :
var data3 = [{label: 'niju', value: 1},{label : 'vivek', value : 2}, ...]; $auto("#employee").autocomplete({source: data3});

2
  • i tried following one but it did`t work var data3=[{label: 'niju', value: 1},{label : 'vivek', value : 2}];
    – kovarthan
    Aug 28, 2013 at 12:21
  • When I test on my part, autocomplete correctly select the right value to use in the input : When tapping an, autocomplete display me two solution (anil and Anil), and on selecting one of them, the correct value (3 or 4 in my example) fill the textfield.
    – vdubus
    Aug 28, 2013 at 13:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.