• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple html:options

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a form which has a single html ption which has all the countries displayed from the database. On selection of the country i have to either display the states / cities depending on the selection.



So the countries are now displayed. Now i wrote an onchange to recognize what is the value of the changed country and then i submit the form to a new action which will fetch either the states/cities depending on my country. I just have one question here. My html:form itself has an onsubmit event that submits to another action .

[code]
<html:form focus="firstName" onsubmit="return validateAll(this)" method="post" action="/register" name="registerForm" type="com.zerodegrees.struts.forms.auth.RegisterFormBean">

What will happen when i submit the form for the onchange of the option ?
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Call a method on "onchange event" and change the action attribute value in the method and submit the form.

Usually in this scenario I have only one action class, which differentiates the requests upon a hidden parameter value, which I set it in the javascript method called on onchange event.

Regards,
Shankar
 
charu latha
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks i got that.

I have one additional question here. If you look at my code i have three id's defined and one ie the name is displayed in the drop down. The id is what is set as the value and based on this value the next fetch happens. However i have another id named as nextstep defined and i need the value of this in the onchange event. I need to pass this to the action class. How do i get this value?

any ideas?
 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<logic:iterate id="countries" name="countArray"> <bean efine id="cntid" name="countries" property="countryId"/> <bean efine id="cntname" name="countries" property="country"/> <bean efine id="nextstep" name="countries" property="nextStep" />
<html ption value="<%=(String)cntid%>"><%=(String)cntname%></html ption></logic:iterate>



Hi,

What you could do is concatenate the cntId and nextStep and put in the value attribute, for ex:



If you see the code, the cntid and nextstep are separated with "-", which you can split them using the "split" of the string class and use them in your program.

Regards,
Shankar
 
charu latha
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

thanks for your input. thats how i planned to do it. However my TA was of the opinion that i could instead take back the value to my bean and iterate over the collection i had built and then pick the nextStep value from there. So i got it done over the weekend.

Once thanks for the input.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic