aspose file tools*
The moose likes Struts and the fly likes How to populate dependant <html:select> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to populate dependant <html:select>" Watch "How to populate dependant <html:select>" New topic
Author

How to populate dependant <html:select>

Sameer Sb
Greenhorn

Joined: Jun 23, 2009
Posts: 2
Hi ,
I have two drop down boxes; one contains "State" and other contains "City".
I wish to populate Cities according to the value selected in State Drop down.
For this I would like to use Ajax to avoid page refresh. And for fetching values in City I am using Struts Action class to give call to server side code.
Does anyone know; How to do this?

Thanks in advance.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Sameer Sb wrote:Does anyone know; How to do this?[/size]

Do you have any knowledge of AJAX, if no, this link will give you start.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sameer Sb
Greenhorn

Joined: Jun 23, 2009
Posts: 2
Hi Sagar,

Thanks for reply.
I know ajax a little bit and know how to build URL and call struts action from a javascript.
I am getting data from my DAO classes format those in Struts Action class in format id,value;id,value;id,value.
Could also separate this in further step by using split and could get id and value in a for loop.
my question is then how to update the dependant <html:select> on the jsp?

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

First thing first, this is not the question for Struts section. Ask AJAX question in HTML-Jsvascript section.
Sameer Sb wrote:
I am getting data from my DAO classes format those in Struts Action class in format id,value;id,value;id,value.

Called JSON
Sameer Sb wrote:my question is then how to update the dependant <html:select> on the jsp?

Once you get that JSON string on client side, evalualte/parse it using function eval() and "write" the HTML or TEXT to select element, something like this


(please look for the correct syntax)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to populate dependant <html:select>