Dynamic Form Elements

Posted on 2007-08-06
Last Modified: 2013-11-24
Is it possible when using a select box to display form elements depending on which option was selected for example:
<option value="d1">Option One</option>
<option value="d2">Option Two</option>
If I selected "Option One" a textbox and a submit button would appear.  For "Option Two" a radio button and a textbox plus a submit button would appear.

If I use a servlet and JSTL and spring how could I get this to work?  I'm new to Java so a detailed description or a tutorial would be great.  I have javascript to make it work but having a problem when submitted the form elements disappear and I have to select option 1 or two again.  

Question by:design_web

    Author Comment

    Or I can use Struts if that would be better.  Even though I don't know Struts well either.
    LVL 14

    Accepted Solution

    You don't need struts, struts can't solve this problem as well.

    Since you have the javascript to render the textbox and button when selecting the select box, what you need is to execute the javascript during page load (<body onload="..">) and pass in the value of the select box from request parameter/attribute, if the value from request is empty then dont do anything in the javascript.



    Author Comment

    I used the onload.  I wish you would of gave me a little more info because it was a lot more involved but the points are yours.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    twoTwo  challenge 35 70
    zeroMAx challenge 20 65
    Junit and TestNG which one is the better for sofware testing 1 28
    mapShare challenge 13 40
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now