Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > urgent deliverable

Reply
Thread Tools

urgent deliverable

 
 
kalyan
Guest
Posts: n/a
 
      10-10-2006
Hi All

I'm a newbie to javascript.
I had a textbox in my webpage.when i try to type something then a list
of matching values should be dispalyed underneath the textbox.
I can provide the list of values thru an array
my requirement seems something like the functionality in the following
site

http://www.google.com/webhp?complete=1&hl=en

Thanks & Regards
Kalyan

 
Reply With Quote
 
 
 
 
Jeremy
Guest
Posts: n/a
 
      10-11-2006
kalyan wrote:
> Hi All
>
> I'm a newbie to javascript.
> I had a textbox in my webpage.when i try to type something then a list
> of matching values should be dispalyed underneath the textbox.
> I can provide the list of values thru an array
> my requirement seems something like the functionality in the following
> site
>
> http://www.google.com/webhp?complete=1&hl=en
>
> Thanks & Regards
> Kalyan
>


Markup (adapt to SGML if XHTML doesn't fit your needs):

<input type="text" id="MyTextBox" />
<!-- absolute position removes it from document flow -->
<select id="MySelect" style="position:absolute">
</select>


Script:

//minimum number of characters to activate autocomplete
var MIN_TEXT_LENGTH = 3;

var MyPossibleValues = ['Lorem', 'LoremTest', 'Ipsum', 'IpsumTest'];

document.getElementById("MyTextBox").onkeypress = function()
{
if(this.value.length < MIN_TEXT_LENGTH)
return;

var selectBox = document.getElementById("MySelect");


//clear select box
while(selectBox.childNodes.length > 0)
selectBox.removeChild(selectBox.childNodes[0]);

//check beginning of each possible value against text box
//case insensitive
for(var i = 0; i < MyPossibleValues.length; i++)
{
if(MyPossibleValues[i].substring(
0, this.value.length).toLowerCase() ==
this.value.toLowerCase())
{
//this option matched
//add it to the select box

var option = document.createElement("option");
option.appendChild(
document.createTextNode(
MyPossibleValues[i]));

selectBox.appendChild(option);
}
}

//make select box expand to fit all the options
//without scrolling
selectBox.size = selectBox.childNodes.length;
}



If you want the select box to change the text box you'll have to add
additional logic for that.

This code is just an example. I didn't even test it and it's probably
riddled with errors and typos.

Jeremy
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
!!URGENT!! Tor Vulnerability Discovered !!URGENT!! Security Advisory Computer Security 1 08-11-2007 09:04 PM
Urgent deliverable kalikoi@gmail.com ASP General 7 08-29-2006 10:40 AM
Urgent Deliverable kalikoi@gmail.com ASP General 2 01-02-2006 10:47 AM
URGENT !! QUEUE STL PROBLEM URGENT!! Sachin Jagtap C++ 4 04-29-2005 12:08 PM
e-mail not deliverable to MSM JERRY TALBERT Computer Support 10 03-03-2004 06:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57