开发者

issue with ajax combox control

i am using ajax combo box control. Here i have items

like

  • kiran james alice dinesh prakash manu

if user type the word like "kushal" as this word is not there in the items of the control this word should not be set in combo box control. but if the word is there in controls it should be allowed to set in the control

hope my Question is clear. thank 开发者_运维技巧 you


I don't really understand your question, is this what you mean?

<input id="name" type="text" onkeyup="selectItem(this.value)" />
<select id="combo">
    <option>kiran</option>
    <option>james</option>
    <option>alice</option>
    <option>dinesh</option>
    <option>prakash</option>
    <option>manu</option>
</select>
<script>
  function selectItem(name){
     var combo = document.getElementById('combo');
     for(var i=0;i<combo.options.length;i++){
        if(combo.options[i].text == name){
           combo.options[i].selected = true;
           combo.selectedIndex = i;
           combo.value = name;
        }
     }
  }
</script>

or the shorter version:

 <input id="name" type="text" onkeyup="document.getElementById('combo').value=this.name;" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜