admin管理员组文章数量:1288126
I have a autoplete on the page using jQuery UI and here is the JSON:
[ {"label":"test1", "value":"1"},
{"label":"testtest", "value":"6"},
{"label":"test2", "value":"8"} ]
The default action of autoplete will grab the value of the item and place into the input box. Is there a way I can stop it? Instead have two separate actions: one inject to a hidden box (with value) and the other to the input box with (label).
$.getJSON('index.php?controller=account&action=getusers', function(data) {
tempJson = data;
$(".auto-search").autoplete({
minLength: 2,
dataType: 'json',
source: tempJson,
select: function (event,ui) {
$('input[name="user-id"]').val(ui.item.value);
}
});
});
I have a autoplete on the page using jQuery UI and here is the JSON:
[ {"label":"test1", "value":"1"},
{"label":"testtest", "value":"6"},
{"label":"test2", "value":"8"} ]
The default action of autoplete will grab the value of the item and place into the input box. Is there a way I can stop it? Instead have two separate actions: one inject to a hidden box (with value) and the other to the input box with (label).
$.getJSON('index.php?controller=account&action=getusers', function(data) {
tempJson = data;
$(".auto-search").autoplete({
minLength: 2,
dataType: 'json',
source: tempJson,
select: function (event,ui) {
$('input[name="user-id"]').val(ui.item.value);
}
});
});
Share
Improve this question
edited Sep 17, 2013 at 15:50
Yuck
50.9k13 gold badges107 silver badges135 bronze badges
asked Dec 9, 2012 at 4:47
BillBill
19.3k21 gold badges88 silver badges135 bronze badges
2 Answers
Reset to default 8Do you mean something like:
........
select: function (event,ui){
$('input[name="user-id"]').val(ui.item.label);
$('input[name="your-hidden-field"]').val(ui.item.value);
return false;
}
This is the actual HTML created by the bobox script:
<p class="dlgline">Select activity:<br>
<select id="biActivity_id" style="display: none;"><option value="1">2015/12/23 14:26 for 1 hour, 3 minutes, Demo</option></select>
<span class="custom-bobox"><input title="" class="custom-bobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autoplete-input" autoplete="off"><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only custom-bobox-toggle ui-corner-right" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>
</p>
<p class="dlgline">Select project:<br>
<select id="biProj_id" style="display: none;"><option value="1">Productive Non Contract</option><option value="2">Non Project Sales</option><option value="3">Waiting Time</option><option value="5">BEL SEM gateway</option><option value="6">Electronic Timesheets</option><option value="7">Fieldbus Speed Module</option><option value="8">Power Management Systems Design</option></select><span class="custom-bobox"><input title="" class="custom-bobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autoplete-input" autoplete="off"><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only custom-bobox-toggle ui-corner-right" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>
</p>
本文标签: javascriptJquery Autocomplete selected valueStack Overflow
版权声明:本文标题:javascript - Jquery Autocomplete selected value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741337354a2373111.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论