You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Olga Agady <oa...@yahoo.com> on 2002/08/13 19:43:13 UTC
Populating select box dynamically
Hello,
In my html:form I have two select boxes: one with the
list of the countries and another one with the list of
states in a country. When the user selects a country I
have to populate the select box with the states for
this country. The list of states I get from the
database. Could someone recommend me the way how I can
do this dynamically? I can write a javascript (which
will be called when the user selects the country) to
populate the state select box, but how can I get the
list of the states in this script from the database?
Is there any possibility to dynamically get data into
javascript from the database? Or there is another way
to implement those two select boxes?
Please help.
Thanks
Olga
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Populating select box dynamically
Posted by James Mitchell <jm...@telocity.com>.
This depends on what you want.
1. Remote Scripting
What is Remote Scripting?
Remote Scripting is the process by which a client-side application running
in the browser and a server-side application can exchange data without
reloading the page. Remote scripting allows you to create complex DHTML
interfaces which interact seamlessly with your server.
http://developer.apple.com/internet/javascript/iframe.html
2. OnClick handler
Use the Onclick event handler within your 'Country' select list to submit
the form to another action that populates the 'States' list based on what
the user selected.
You can reuse the same jsp. It's really quite simple.
I hope that help you.
James Mitchell
Software Engineer\Struts Evangelist
Struts-Atlanta, the "Open Minded Developer Network"
http://www.open-tools.org/struts-atlanta
> -----Original Message-----
> From: Olga Agady [mailto:oagady@yahoo.com]
> Sent: Tuesday, August 13, 2002 10:50 PM
> To: Struts Users Mailing List
> Subject: Re: Populating select box dynamically
>
>
> Hi, Fabio
>
> Thanks for the tip. Unfortunately it is not going to
> work for me. I don't have the list of all possible
> options for the second box until the selection in
> first bos is made. I need to get them from the
> database after I know which country was selected.
>
> However I found the answer in Struts users archive - I
> have to use Javascript to detect choices in the first
> select list and submit the form from this script. In
> the Action that receives the form, I will check the
> value of a hidden variable to see if this submit is
> for the redisplaying the same jsp with newly populated
> second box or this is a final "submit". If this is for
> redisplaying - Action gets the data for the second box
> from the database and forwards back to the same jsp
> with updated values.
>
> Regards
> Olga
>
> --- Fabio_Silva <fa...@chipidea.com> wrote:
> > Hello,
> >
> > I had the same problem, but I didn't manage to solve
> > it using only struts.
> >
> > Nevertheless, I found an interesting Javascript
> > chunk of code that
> > solved my problem:
> >
> > Go to:
> >
> >
> http://www.mattkruse.com/javascript/dynamicoptionlist/
> >
> > If you have problems adapting this to struts, please
> > tell me. I can
> > arrange for a code example.
> >
> > Hope this helps,
> > Fabio
> >
> >
> > Olga Agady wrote:
> > > Hello,
> > >
> > > In my html:form I have two select boxes: one with
> > the
> > > list of the countries and another one with the
> > list of
> > > states in a country. When the user selects a
> > country I
> > > have to populate the select box with the states
> > for
> > > this country. The list of states I get from the
> > > database. Could someone recommend me the way how I
> > can
> > > do this dynamically? I can write a javascript
> > (which
> > > will be called when the user selects the country)
> > to
> > > populate the state select box, but how can I get
> > the
> > > list of the states in this script from the
> > database?
> > > Is there any possibility to dynamically get data
> > into
> > > javascript from the database? Or there is another
> > way
> > > to implement those two select boxes?
> > >
> > > Please help.
> > >
> > > Thanks
> > > Olga
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > HotJobs - Search Thousands of New Jobs
> > > http://www.hotjobs.com
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> HotJobs - Search Thousands of New Jobs
> http://www.hotjobs.com
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Populating select box dynamically
Posted by Olga Agady <oa...@yahoo.com>.
Hi, Fabio
Thanks for the tip. Unfortunately it is not going to
work for me. I don't have the list of all possible
options for the second box until the selection in
first bos is made. I need to get them from the
database after I know which country was selected.
However I found the answer in Struts users archive - I
have to use Javascript to detect choices in the first
select list and submit the form from this script. In
the Action that receives the form, I will check the
value of a hidden variable to see if this submit is
for the redisplaying the same jsp with newly populated
second box or this is a final "submit". If this is for
redisplaying - Action gets the data for the second box
from the database and forwards back to the same jsp
with updated values.
Regards
Olga
--- F�bio_Silva <fa...@chipidea.com> wrote:
> Hello,
>
> I had the same problem, but I didn't manage to solve
> it using only struts.
>
> Nevertheless, I found an interesting Javascript
> chunk of code that
> solved my problem:
>
> Go to:
>
>
http://www.mattkruse.com/javascript/dynamicoptionlist/
>
> If you have problems adapting this to struts, please
> tell me. I can
> arrange for a code example.
>
> Hope this helps,
> F�bio
>
>
> Olga Agady wrote:
> > Hello,
> >
> > In my html:form I have two select boxes: one with
> the
> > list of the countries and another one with the
> list of
> > states in a country. When the user selects a
> country I
> > have to populate the select box with the states
> for
> > this country. The list of states I get from the
> > database. Could someone recommend me the way how I
> can
> > do this dynamically? I can write a javascript
> (which
> > will be called when the user selects the country)
> to
> > populate the state select box, but how can I get
> the
> > list of the states in this script from the
> database?
> > Is there any possibility to dynamically get data
> into
> > javascript from the database? Or there is another
> way
> > to implement those two select boxes?
> >
> > Please help.
> >
> > Thanks
> > Olga
> >
> > __________________________________________________
> > Do You Yahoo!?
> > HotJobs - Search Thousands of New Jobs
> > http://www.hotjobs.com
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Populating select box dynamically
Posted by Fábio Silva <fa...@chipidea.com>.
Hello,
I had the same problem, but I didn't manage to solve it using only struts.
Nevertheless, I found an interesting Javascript chunk of code that
solved my problem:
Go to:
http://www.mattkruse.com/javascript/dynamicoptionlist/
If you have problems adapting this to struts, please tell me. I can
arrange for a code example.
Hope this helps,
Fábio
Olga Agady wrote:
> Hello,
>
> In my html:form I have two select boxes: one with the
> list of the countries and another one with the list of
> states in a country. When the user selects a country I
> have to populate the select box with the states for
> this country. The list of states I get from the
> database. Could someone recommend me the way how I can
> do this dynamically? I can write a javascript (which
> will be called when the user selects the country) to
> populate the state select box, but how can I get the
> list of the states in this script from the database?
> Is there any possibility to dynamically get data into
> javascript from the database? Or there is another way
> to implement those two select boxes?
>
> Please help.
>
> Thanks
> Olga
>
> __________________________________________________
> Do You Yahoo!?
> HotJobs - Search Thousands of New Jobs
> http://www.hotjobs.com
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>