• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to populate dependant <html:select>

 
Sameer Sb
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sameer Sb
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic