By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

Could AJAX help here?

P: n/a
Hi,

I have two <SELECT> elements on my page. I want to use the first to
populate the second. That is, upon selecting an option from the first,
I want the second to populate with items. Ideally, I'd prefer not to
reload the page and thus using JSP to populate hte second menu. Is
there a way, using Javascript, that I can invoke some server-side
functionality and get the populate the menu?

Thanks, -

Jun 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
la***********@zipmail.com wrote:
Hi,

I have two <SELECT> elements on my page. I want to use the first to
populate the second. That is, upon selecting an option from the
first, I want the second to populate with items. Ideally, I'd prefer
not to reload the page and thus using JSP to populate hte second
menu. Is there a way, using Javascript, that I can invoke some
server-side functionality and get the populate the menu?


Yes, AJAX could easily solve this.

Just as simple is to generate the javascript code for a two-dimensional
array (or an array of array for the purists) where you put the entries
for the first selection in the first dimension, and and array for each
item for the second selection in the second dimension.

Then use Javascript on the client to fill the select elements from the
first dim. Then onclick, use JS to fill the second from the corresponding
second dim.

--
Dag.

Jun 22 '06 #2

P: n/a
.
To see the "test - Ajax" on:

LWA - LocaWapp - localhost web applications
http://daviderognoni.blogspot.com/?locawapp
la***********@zipmail.com ha scritto:
Hi,

I have two <SELECT> elements on my page. I want to use the first to
populate the second. That is, upon selecting an option from the first,
I want the second to populate with items. Ideally, I'd prefer not to
reload the page and thus using JSP to populate hte second menu. Is
there a way, using Javascript, that I can invoke some server-side
functionality and get the populate the menu?

Thanks, -


Jun 22 '06 #3

P: n/a
la***********@zipmail.com wrote:
I have two <SELECT> elements on my page. I want to use the first to
populate the second.


This is a perfect place for Ajax.

Or, depending on your situation, you can populate the page will all possible
options and populate the second select entirely with javascript. In general,
Ajax is less available on internet browsers than javascript (since Ajax in
IE is ActiveX which gets disabled more frequently than javascript as a
whole) so using the javascript method may reach slightly more users. If
you're in a controlled environment, then it may not matter.

A javascript-only solution can be found here:
http://www.javascripttoolbox.com/lib/dynamicoptionlist/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.