473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Help with refreshing the options in a DD depending on user input

157 100+
Hi,

I'm working with JavaScript, JSP and Servlets.
I have attached here a snapshot of a portion of my webpage which is a JSP.

I need that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear in the DD located below.
Like say if I just key in 'J' then all the student-names from the "Names - table(backend-MySql)" starting with 'J' have to appear in the DD, say if I'm typing in "Jo" then just names such as "John"," Joanna" etc need appear .. this is much like when we
send emails ...wherein automatically the matching entries for the typed-in address show up from our address book in a dropdown list below the "To" textbox..

So far using JSP + Javascript I’ve achieved that if a person types in just “J” in the textbox then all the names starting with “J” do appear in the DD ..but as he goes on typing further the entries quickly need to be further filtered based on whatever he is typing..

Has anyone ever worked on something like this before, please send me your suggestions..

Thanks,

P.S:- Is it possible that on the onFocus() event of the textbox my JSP make a request to the server and get the refreshed list of matching names. .i.e. I mean like every time the user types in some letter in the textbox the JSP executes some select-where query and gets the matching names from the database right away?
Attached Images
File Type: jpg snapshot.jpg (3.9 KB, 107 views)
Jan 12 '07 #1
1 932
r035198x
13,262 8TB
Hi,

I'm working with JavaScript, JSP and Servlets.
I have attached here a snapshot of a portion of my webpage which is a JSP.

I need that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear in the DD located below.
Like say if I just key in 'J' then all the student-names from the "Names - table(backend-MySql)" starting with 'J' have to appear in the DD, say if I'm typing in "Jo" then just names such as "John"," Joanna" etc need appear .. this is much like when we
send emails ...wherein automatically the matching entries for the typed-in address show up from our address book in a dropdown list below the "To" textbox..

So far using JSP + Javascript I’ve achieved that if a person types in just “J” in the textbox then all the names starting with “J” do appear in the DD ..but as he goes on typing further the entries quickly need to be further filtered based on whatever he is typing..

Has anyone ever worked on something like this before, please send me your suggestions..

Thanks,

P.S:- Is it possible that on the onFocus() event of the textbox my JSP make a request to the server and get the refreshed list of matching names. .i.e. I mean like every time the user types in some letter in the textbox the JSP executes some select-where query and gets the matching names from the database right away?
The answer to the last part of your question is no. Javascript is compiled client side.

This is an all javascript issue but I'll give you a solution here and copy the thread to the js forum for others' comments

[PHP]
//ordinaryAutoComplete.js
function ordinaryAutoComplete (field, select, property, forcematch) {
var found = false;
for (var i = 0; i < select.options.length; i++) {
if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
found=true;
break;
}
}
if (found) {
select.selectedIndex = i;
}
else {
select.selectedIndex = -1;
alert("Search string not found");

}
if (field.createTextRange) {
if (forcematch && !found) {
field.value=field.value.substring(0,field.value.le ngth-1);
return;
}
var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
if (cursorKeys.indexOf(event.keyCode+";") == -1) {
var r1 = field.createTextRange();
var oldValue = r1.text;
var newValue = found ? select.options[i][property] : oldValue;
if (newValue != field.value) {
field.value = newValue;
var rNew = field.createTextRange();
rNew.moveStart('character', oldValue.length) ;
rNew.select();
}
}
}
}
[/PHP]
the names input goes something like

[HTML]<input name ="name" onkeyup="ordinaryAutoComplete(this,this.form.optio ns1,'text',true)">[/HTML]
Drop down name in the html is options1
Jan 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
10
by: abctech | last post by:
Hi all, I’m training in Servlets, JSP and JavaScript,. Here is a snapshot of a portion of my web page, there’s a “StudentName” textbox and below it is a “Names” Dropdown list. The...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.