...

View Full Version : Intellisense feature using javascript



rktaiwala
07-10-2012, 10:53 AM
I want to create my own intellisense feature using javascript. (i.e.) When i type letter '.',it should display in drop down box containing predefined list or array.
The drop down should be displayed only when '.' is typed and the drop down should be visible until either one element is selected or enter is pressed.
and the process continues.
I tries Jquery UI autocomplete but didn't work to my expectation.
Any idea how to achieve it.
Thanks in advance

Philip M
07-10-2012, 12:20 PM
<input type = "text" id = "txt1" onkeyup = "chk(event)">
<br><br>

<div id = "mydiv" style="display:none">

<select id = "mysel" onchange = "getValue()">
<option value = "">Choose ...</option>
<option value = "A">A</option>
<option value = "B">B</option>
<option value = "C">C</option>
<option value = "D">D</option>
</select>
</div>

<script type = "text/javascript">

function chk(ev) {
var key;
ev = ev || event;
key = ev.keyCode;
if (key == 13) { // enter key
document.getElementById("mydiv").style.display="none"; // hide the select list if enter key is pressed
return false;
}

var x = document.getElementById("txt1").value;
var len = x.length;
var last = x.charAt(len-1);
if (last == ".") {
document.getElementById("mydiv").style.display="block"; // show the select list
document.getElementById("txt1").value = x.substring(0,len-1); // erase the final period
}
}

function getValue() {
var val = document.getElementById("mysel").value;
if (val != "") {
alert ("You chose " + val); // for testing;
document.getElementById("mydiv").style.display="none"; // hide the select list
}
}

</script>

Caller: "I deleted a file from my PC last week and I have just realised that I need it. If I turn my system clock back two weeks will I have my file back again?".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum