自动填充下拉列表 [英] Auto populate the Dropdown List

查看:68
本文介绍了自动填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在接受Servlets,JSP和JavaScript的培训,


我有一个网页,其中有''sa''StudentName"文本框和

以下是名称下拉列表。最初文本框是空的

而Dropdown没有任何项目..


要求是只要一个人继续在
StudentName-textbox相应的匹配名称必须在下面的DD中显示



如果我只是键入''J' '那么所有的学生姓名来自

" Names - table(backend-MySql)"从''J'开始必须在DD中出现

,比如说我输入的是Jo。然后只是名称,如

" John","乔安娜"等等需要出现..这就像我们

发送电子邮件...其中

输入地址的匹配条目自动显示在我们的地址簿中下面的下拉列表

To文本框..


任何人都可以帮我提一下这个建议...


PS: - 是否也可以通过Java / JavaScript来实现将特定的

控件直接链接到某个数据库表?

例如我可以直接将DD链接到后端表,并且每次添加/删除

表而不是整个页面时,只需刷新下拉菜单。 。


谢谢,

Hi All,

I''m training in Servlets, JSP and JavaScript,

I have a web page in which there''s a "StudentName" 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,

推荐答案

Googlejavascript + live search。几乎你将要做什么

是:当他们输入时,你将向服务器请求数据库中的所有

条目,平面文件。 。这类似于你的

文本区域中的内容。然后,您想清空并重新创建

下拉列表中的选项。您可以找到使用JSP和

JavaScript的代码示例。

eureka写道:
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:

大家好,


我正在接受Servlets,JSP和JavaScript的培训,


我有一个网页,其中有一个" StudentName"文本框和

以下是名称下拉列表。最初文本框是空的

而Dropdown没有任何项目..


要求是只要一个人继续在
StudentName-textbox相应的匹配名称必须在下面的DD中显示



如果我只是键入''J' '那么所有的学生姓名来自

" Names - table(backend-MySql)"从''J'开始必须在DD中出现

,比如说我输入的是Jo。然后只是名称,如

" John","乔安娜"等等需要出现..这就像我们

发送电子邮件...其中

输入地址的匹配条目自动显示在我们的地址簿中下面的下拉列表

To文本框..


任何人都可以帮我提一下这个建议...


PS: - 是否也可以通过Java / JavaScript来实现将特定的

控件直接链接到某个数据库表?

例如我可以直接将DD链接到后端表,并且每次添加/删除

表而不是整个页面时,只需刷新下拉菜单。 。


谢谢,
Hi All,

I''m training in Servlets, JSP and JavaScript,

I have a web page in which there''s a "StudentName" 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,


eureka于2007年1月11日在comp.lang.javascript中写道
eureka wrote on 11 jan 2007 in comp.lang.javascript:

是否也可以通过Java / JavaScript将特定的

控件直接链接到某个数据库表?
Is it also possible through Java/JavaScript to link a particular
control directly to some database table?



Javascript与Java无关但名称。


什么是控制?

将这样的东西链接到数据库表会有什么用?

Clientside javascript通常无法访问[服务器端]数据库,

如果我们正在谈论网页[是吗?]


这个NG适用于Javascript,如果没有特别说明,

客户端javascript on / in a internet web page
-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)

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)


Curtis.Dani ... @ gmail.com写道:
Curtis.Dani...@gmail.com wrote:

Googlejavascript + live search。几乎你将要做什么

是:当他们输入时,你将向服务器请求数据库中的所有

条目,平面文件。 。这类似于你的

文本区域中的内容。然后,您想清空并重新创建

下拉列表中的选项。您可以找到使用JSP和

JavaScript的代码示例。
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.





感谢您的回复..


您已经建议如下用户在文本框中键入一些字母

请求服务器输入匹配的数据库条目,好吧我

我不确定这是否可以通过客户端获得

JavaScript(CSJS)或者使用JSP,如果我没有错误的JSP文件
从浏览器运行的
转换为java servlet,然后

将servlet编译为.class文件然后运行,但不像

Javascript中每次发生事件时Jsp中的代码都没有执行

Html页面,它只会在页面请求中首先执行,然后在每次刷新页面时再次执行


我的意思是每一个时间用户输入的内容或其他内容

文本框我认为至少Jsp / CSJS代码无法向服务器发出

请求以获取记录。我还是我不太确定

这是因为我还在学习......如果有人对如何实现这一点有进一步的了解,请建议,


我的想法是,可能通过JSP我可以在页面请求

本身获得与数据库的连接并从

Names-table并可能将它们存储在我页面上的隐藏字段中,然后

然后在文本框的每个onFocus()事件中我都可以检索文本

键入文本框中的某个变量,并将该文本的第一个字母

与我的

隐藏字段中的所有名字的第一个字母逐个进行比较,然后无论名字匹配我只是填充

他们进入DD ..但这只达到了目的的一半......除了每个onFocus()事件,每个onbocus()事件的JavaScript函数将是我认为这可能会导致开销!


我已经也有人建议使用AJAX,但之前从未使用它,所以如果any1提供任何有关相同的建议,我将不胜感激。

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

这篇关于自动填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆