473,725 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto populate the Dropdown List

Hi All,

I'm training in Servlets, JSP and JavaScript,

I have a web page in which there's a "StudentNam e" textbox and
below it is a "Names" Dropdown list. Initially the Textbox is empty
and the Dropdown doesnt have any items..

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 ..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..

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 the backend-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
11 7394
Google "javascript + live search". Pretty much what you'll be doing
is: as they type you will be making a request to a server for all
entries in a database, flat file... that are similar to what is in your
text area. You then want to empty and recreate the options in your
dropdown list. You can probably find code samples that use JSP and
JavaScript to do it.
eureka wrote:
Hi All,

I'm training in Servlets, JSP and JavaScript,

I have a web page in which there's a "StudentNam e" textbox and
below it is a "Names" Dropdown list. Initially the Textbox is empty
and the Dropdown doesnt have any items..

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 ..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..

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 the backend-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 #2
eureka wrote on 11 jan 2007 in comp.lang.javas cript:
Is it also possible through Java/JavaScript to link a particular
control directly to some database table?
Javascript has nothing to do with Java but the name.

What is a "control"?
What would be the use linking such thing to a database table?

Clientside javascript usually cannot reach a [serverside] database,
if we are talking web pages [do you?]

This NG is for Javascript, and if not specifically stated otherwise,
clientside javascript on/in an internet web page is ment.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 11 '07 #3
Curtis.Dani...@ gmail.com wrote:
Google "javascript + live search". Pretty much what you'll be doing
is: as they type you will be making a request to a server for all
entries in a database, flat file... that are similar to what is in your
text area. You then want to empty and recreate the options in your
dropdown list. You can probably find code samples that use JSP and
JavaScript to do it.
Hi
Thanks for your reply..

You've suggested that as the user types in some letters in the textbox
request be made to the server for the matching database entries, well I
am not sure if this can be acheived through Client Side
JavaScript(CSJS ) or with JSP either coz if I' m not wrong the JSP file
that you run from the browser is converted into a java servlet, then
the servlet is compiled to a .class file and then its run, but unlike
Javascript the code in Jsp in not executed everytime an event occurs on
the Html page, it'l only be executed first on the page-request and then
again on every refresh for that page.
What I mean is every time the user types in something or the other in
the textbox I think atleast the Jsp/CSJS code wont be able to make a
request to the server for the records..well I'm not very sure about
this since I'm still learning ...if anyone has a further idea as to how
this can be achieved please suggest,

What I had in mind was that maybe through JSP I could on page request
itself get a connection to the database and collect all the Names from
the Names-table and maybe store them in a hidden field on my page and
then on every onFocus() event of the textbox I could retrieve the text
keyed in 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..beside s on
every onFocus() event the JavaScript function will be called which will
do the matching, I think that'l probably cause overhead !

I've also been suggested AJAX, but never worked with it before so I'd
be grateful if any1 provides any suggestions regarding the same.

Jan 11 '07 #4
Curtis.Dani...@ gmail.com wrote:
Google "javascript + live search". Pretty much what you'll be doing
is: as they type you will be making a request to a server for all
entries in a database, flat file... that are similar to what is in your
text area. You then want to empty and recreate the options in your
dropdown list. You can probably find code samples that use JSP and
JavaScript to do it.
Hi
Thanks for your reply..

You've suggested that as the user types in some letters in the textbox
request be made to the server for the matching database entries, well I
am not sure if this can be acheived through Client Side
JavaScript(CSJS ) or with JSP either coz if I' m not wrong the JSP file
that you run from the browser is converted into a java servlet, then
the servlet is compiled to a .class file and then its run, but unlike
Javascript the code in Jsp in not executed everytime an event occurs on
the Html page, it'l only be executed first on the page-request and then
again on every refresh for that page.
What I mean is every time the user types in something or the other in
the textbox I think atleast the Jsp/CSJS code wont be able to make a
request to the server for the records..well I'm not very sure about
this since I'm still learning ...if anyone has a further idea as to how
this can be achieved please suggest,

What I had in mind was that maybe through JSP I could on page request
itself get a connection to the database and collect all the Names from
the Names-table and maybe store them in a hidden field on my page and
then on every onFocus() event of the textbox I could retrieve the text
keyed in 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..beside s on
every onFocus() event the JavaScript function will be called which will
do the matching, I think that'l probably cause overhead !

I've also been suggested AJAX, but never worked with it before so I'd
be grateful if anyone provides any suggestions regarding the same.

Jan 11 '07 #5
Evertjan. wrote:
Javascript has nothing to do with Java but the name.

What is a "control"?
What would be the use linking such thing to a database table?

Clientside javascript usually cannot reach a [serverside] database,
if we are talking web pages [do you?]

This NG is for Javascript, and if not specifically stated otherwise,
clientside javascript on/in an internet web page is ment.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Hi there,
Thanks for your reply.

By control I actually meant some Html form component..like a DropDown
List ..

I have on my web page a DD displaying the names of all the students
studying in an institute, but I need that at runtime say if any of
these students were to be deleted or new ones added (in the backend)
then without refreshing the entire page the changes be reflected in the
corresponding DD..

I am aware that this cant exactly be achieved through CSJS..but I'm
still learning so just wanted to check if there was any alternative at
all.

Jan 11 '07 #6

Evertjan. wrote:
JavaSript has nothing to do with Java but the name.
>
What is a "control"?
What would be the use linking such thing to a database table?

Clientside javascript usually cannot reach a [serverside] database,
if we are talking web pages [do you?]

This NG is for Javascript, and if not specifically stated otherwise,
clientside javascript on/in an internet web page is ment.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Hi there,
Thanks for your reply.

By control I actually meant some Html form component..like a DropDown
List ..
I have on my web page a DD displaying the names of all the students
studying in an institute, but I need that at runtime say if any of
these students were to be deleted or new ones added (in the backend)
then without refreshing the entire page the changes be reflected in the

corresponding DD..
I am aware that this cant exactly be achieved through CSJS..but I'm
still learning so just wanted to check if there was any alternative at
all.

Jan 11 '07 #7
eureka said the following on 1/11/2007 12:13 PM:
Curtis.Dani...@ gmail.com wrote:
>Google "javascript + live search". Pretty much what you'll be doing
is: as they type you will be making a request to a server for all
entries in a database, flat file... that are similar to what is in your
text area. You then want to empty and recreate the options in your
dropdown list. You can probably find code samples that use JSP and
JavaScript to do it.

Hi
Thanks for your reply..

You've suggested that as the user types in some letters in the textbox
request be made to the server for the matching database entries, well I
am not sure if this can be acheived through Client Side
JavaScript(CSJS )
Yes it can.
or with JSP either coz if I' m not wrong the JSP file
that you run from the browser is converted into a java servlet, then
the servlet is compiled to a .class file and then its run, but unlike
Javascript the code in Jsp in not executed everytime an event occurs on
the Html page, it'l only be executed first on the page-request and then
again on every refresh for that page.
Page makes a silent request to the .jsp file, the .jsp file executes on
the server and returns the new list to the browser. The browser then
updates the dropdown. Google uses it.
What I mean is every time the user types in something or the other in
the textbox I think atleast the Jsp/CSJS code wont be able to make a
request to the server for the records..well I'm not very sure about
this since I'm still learning ...if anyone has a further idea as to how
this can be achieved please suggest,
There are several ways, all of which involve requesting a new list from
the server. The difference in the approach would be how you wanted to
transmit that data and how you would handle it on the client.
What I had in mind was that maybe through JSP I could on page request
itself get a connection to the database and collect all the Names from
the Names-table and maybe store them in a hidden field on my page and
then on every onFocus() event of the textbox I could retrieve the text
keyed in 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..beside s on
every onFocus() event the JavaScript function will be called which will
do the matching, I think that'l probably cause overhead !
Calling the onfocus event won't be the overhead. Trying to retrieve
every word in the database that starts with a letter or two letter
combination would be the overhead. User types the letter A and you
retrieve every word starting with A, and so on.
I've also been suggested AJAX, but never worked with it before so I'd
be grateful if anyone provides any suggestions regarding the same.
AJAX is a buzz word that nearly encompasses any act of getting data from
the server without refreshing the page. That's all. The XMLHttpRequest
object (that AJAX was originally based on) is but one method of getting
data from the server.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 11 '07 #8
eureka wrote on 11 jan 2007 in comp.lang.javas cript:
Evertjan. wrote:
>Javascript has nothing to do with Java but the name.

What is a "control"?
What would be the use linking such thing to a database table?

Clientside javascript usually cannot reach a [serverside] database,
if we are talking web pages [do you?]

This NG is for Javascript, and if not specifically stated otherwise,
clientside javascript on/in an internet web page is ment.
By control I actually meant some Html form component..like a DropDown
List ..

I have on my web page a DD displaying the names of all the students
studying in an institute, but I need that at runtime say if any of
these students were to be deleted or new ones added (in the backend)
then without refreshing the entire page the changes be reflected in the
corresponding DD..

I am aware that this cant exactly be achieved through CSJS..but I'm
still learning so just wanted to check if there was any alternative at
all.
Anything like that can be done with clientside javascript, when the
corresponding serverside will deliver the neccessary data.

See Randy's answer elsewhere.

However, you should concider if the gain of using an AJAX/xmlhttp like
construction is worth it against rerequesting a page,
If you download aal the students data anyway.

More interesting would be, if you could request via Ajax just the few
students that should be left out of the primary list.

Then a DOM guided search and delete of some drop down list <option>s
could be a quicky, and could even be done with some display of clientside
firework.

Using AJAX/xmlhttp tricks seems only wothwhile if the amount of data
requested is very small in comparison to the page download size,
and/or the dynamicity required is high. Or if the page has inmages that
you do not want to blink. [Other options, anyone?]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 11 '07 #9
eureka wrote:
I have a web page in which there's a "StudentNam e" textbox and
below it is a "Names" Dropdown list. Initially the Textbox is empty
and the Dropdown doesnt have any items..

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 ..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..
<form>
<input type="text" name="StudentNa me"
style="text-transform:upper case" onKeyUp="
while (s.options.leng th) s.options[0] = null
for (i=0; i<v.length; ++i)
if (new RegExp('^'+(thi s.value).toUppe rCase()).exec(v[i]))
s.options[s.length] = new Option(v[i],v[i])">
<select size="1" name="Names" style="width:25 0px"></select>
</form>
<script type="text/javascript">
v = new Array('J\'K','J A','JA F','JAN','JAP', 'JAPI/','JO','JOS')
s = document.forms[0].Names
</script>

Entries may not contain ()\|^$?.{}!+* - it should be pretty easy to
filter them out.

Hope this helps,

--
Bart

Jan 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3609
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be populated in same JSP page. I have a java bean called officeBean that contains all the office information.
0
1753
by: george d lake | last post by:
Hi, Is there a way to have a "Auto Complete" textbox or a "editable" dropdown? Here is my problem. I have a screen that need to have a list of 800+ employees. To be a dropdown, that could be a lot of scrolling. and to enter the name in a textbox leaves too many possible typos. So, is there a control that will do a auto complete in the textbox as I type the name or have a combo box that I could type and auto complete like in VB?
6
2354
by: Smithers | last post by:
I am looking to implement a search feature into a Windows Forms MDI application. Specifically I plan to embed 3 textboxes into a toolbar; one for LastName, another for FirstName, and one for CustomerID. When the user starts typing into any of these textboxes I would like to pop up another form that shows the user a dynamic list of the closest matches. The user can then use the up- and down-arrow keys to select a customer from that pop up...
0
1613
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp textbox control which has a 'TextMode' property and when clicked on, displays as a dropdown list with 3 values, I want to have a similar type property with a dropdown style.
2
6066
by: Abdhul Saleem | last post by:
Hi, Any code snippet or help link available on how to auto resize the dropdown list part of the combo(<select>) ? Or, is there any alternative techniques for displaying the full lenth text when dropdown the combo? Regards, M. Abdhul Saleem.
5
17682
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600. The species list has 7 fields the first is a four digit unique identifier (species) it is set as the primary key. I have created a relationship to the data collection table which also has a species field (4 digit id). In my form I have the species...
1
1872
by: fran7 | last post by:
Hi, Anyone know how to populate a dropdown list with data from database. I have an interface that generates the following code for names in my database. ..asp <%If Trim(rsCard("Author"))<>"" Then%> <%=rsCard("Author")%><%End If%> .. How does one populate a dropdown list??
4
4844
by: olidenia | last post by:
I need some help or tips on the following. I have a .sql database file with the folowing structure: DROP TABLE IF EXISTS `car`; CREATE TABLE IF NOT EXISTS `car` ( `id` int(10) default NULL, `Make` text, `Model` text,
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.