仅从自动填充列表中选择项目 [英] Select item from autocomplete list only
问题描述
我有一个表单,其中我有一个文本,显示自动完成列表使用ajax.i我在自动完成列表中连接id,名称和地址,这样id / name-address.i必须拆分,id名称用户在文本框的文本更改事件中选择它后,可以使用此自动完成列表项的地址以供更进一步使用。问题是如果用户键入任何随机文本并且不从自动完成列表中选择,我得到一个例外bcoz字符串不会拆分。我怎么能防止这个?帮助我。
提前感谢..
您好,
您需要调用JavaScript函数文本框的OnBlur()事件
例如你的字符串是:01 /姓名地址
<前lang =HTML> < < span class =code-leadattribute> asp:textbox id = txtAutoComplete runat = server onblur = return validateAutoComplete(this); tabindex = < span class =code-keyword> 3 xmlns:asp = #unknown > < / asp:textbox >
function validateAutoComplete(el){
var str = el.value
var n = str.indexOf( /);
var l = str.indexOf( - 跨度>);
if (n == -1 || l == -1){
el.value = ;
}
其他 {
return 真跨度>;
}
}
将ReadOnly设为True。这将阻止用户输入任何内容
i have a form in which i have a text which shows autocomplete list using ajax.i am concatenating id,name and address in my autocomplete list in this way "id/name-address".i have to split,id name and address from this autocomplete list item after user selects it on text change event of textbox for furthur use.The problem is if user types any random text and doesnt select from autocomplete list ,i get an exception bcoz the string doesnt split.How can i prevent this? Help Me.
thanks in advance..
Hi,
You need to call JavaScript function on OnBlur() event of textbox
like e.g. your string is: 01/Name-Address
<asp:textbox id="txtAutoComplete" runat="server" onblur="return validateAutoComplete(this);" tabindex="3" xmlns:asp="#unknown"></asp:textbox>
function validateAutoComplete(el) { var str = el.value var n = str.indexOf("/"); var l = str.indexOf("-"); if (n == -1 || l == -1) { el.value = ""; } else { return true; } }
Make ReadOnly to True. This will stop the user from entering anything
这篇关于仅从自动填充列表中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!