473,320 Members | 2,107 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,320 software developers and data experts.

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

157 100+
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 requirement is 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 ..

What I had in mind is that maybe through JSP I could on page load itself collect all the Names from the Names-table and maybe store them in a hidden field on my page itself and then on the onFocus() event of the textbox I could retrieve the text keyed into the textbox into some variable and compare the first letter of that text with the first letter of all the names present in my hidden field one by one and then whatever names match I just populate them into the DD ..but this achieves only half the purpose …

Can anyone help me with suggestions regarding this…

P.S:- Is it also possible through Java/JavaScript to link a particular control directly to some database table?
For e.g. can I directly link a DD to some table and have just the dropdown refreshed every time there was an addition/deletion to the table and not the whole page..

Thanks,
Jan 11 '07 #1
10 1710
AricC
1,892 Expert 1GB
Java and Javascript are two completely seperate things. For your search box I think you are talking about AJAX.

HTH,
Aric
Jan 11 '07 #2
abctech
157 100+
Java and Javascript are two completely seperate things. For your search box I think you are talking about AJAX.

HTH,
Aric
Hi, Yes Java and JavaScript are indeed different altogether, but I was sort of confused as to which forum this question belongs to , and besides I have never worked with Ajax before but I'l check out the link ..Thanks!
Jan 11 '07 #3
abctech
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, 180 views)
Jan 12 '07 #4
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 #5
abctech
157 100+
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
Hi r0,
Thanx a lot for your prompt response, I am looking into the code you've provided .I thought this was a JS issue too hence posted this query in the JS forum at first but didnot get any concrete reply hence reposted it in the ever so helpful Java forum.

Thanks again!
Jan 12 '07 #6
b1randon
171 Expert 100+
The answer to the last part of your question is no. Javascript is compiled client side.
JavaScript is an interpreted language. It is <b>run</b> on the client side in a line by line fashion. It is never compiled. It is a common problem with terminology. You probably meant that the code get executed but said compiled which it really isn't.
Jan 12 '07 #7
r035198x
13,262 8TB
JavaScript is an interpreted language. It is <b>run</b> on the client side in a line by line fashion. It is never compiled. It is a common problem with terminology. You probably meant that the code get executed but said compiled which it really isn't.
Thanks for the correction mate. You are right there is certainly no such thing as a Javascript compiler. I should be more careful with my terminology.
Jan 13 '07 #8
b1randon
171 Expert 100+
Thanks for the correction mate. You are right there is certainly no such thing as a Javascript compiler. I should be more careful with my terminology.
No harm, no foul ^^
Jan 13 '07 #9
abctech
157 100+
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
Thanks a lot for the above code r0..its working wonderfully ! Amazing logic !!!
Jan 20 '07 #10
r035198x
13,262 8TB
Thanks a lot for the above code r0..its working wonderfully ! Amazing logic !!!
Good to know it helped.
Jan 20 '07 #11

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

Similar topics

3
by: Paul Eghbal | last post by:
Hi all, I'm trying to use the following script: <script language="javaScript"> function setrepto(){ document.aForm.repno.value = document.aForm.rep.options.value; } </script>
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 -------------------------------------------------------------------------------- ...
2
by: maricel | last post by:
Is there any advantage in terms of performance when activating intra-parallelism INTRA_PARALLEL = yes DFT_DEGREE = -1 for a Windows 2K, sigle (1) CPU server. The database is used for a small...
15
by: Buck Rogers | last post by:
Hi guys! Task 1: Write a program which presents a menu with 5 options. The 5th option quits the program. Each option should execute a system command using system(). Below is my humble...
5
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
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...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: abctech | last post by:
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...
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
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.