Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JSP Form question

Options
  • 24-04-2006 3:03pm
    #1
    Registered Users Posts: 3,012 ✭✭✭


    Hey,
    have a problem with a page I'm trying to develop.

    Is there any way to assign the current value of a form object, ie text or selected option to a variable defined in the same JSP before it's submitted.

    I'm designing in Struts, and I already have a FormBean ready, but I want to use the selected values on the page, before the user submits.

    Cheers.


Comments

  • Closed Accounts Posts: 255 ✭✭full forward


    Use javascript. eg

    <SELECT name="mySelect" onChange="myfunction();">
    <option value= .......
    </SELECT>

    <script>
    function myfunction()
    {
    thatbox = document.forms[0].mySelect;
    alert('you selected ' + thatbox.value);
    }
    </script>


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    I've tried the javascript aproach, but it wont work as I cant assign a name to the select tag.
    It causes a conflict with the struts actionform bean.

    Is there anyway I can use the formbean values before they are submitted?


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    Got it working. Stopped using the <HTML:Select> tag, so i was able to name the field.


  • Registered Users Posts: 1,996 ✭✭✭lynchie


    You should really be using the <html:select/> tags as they are reduce the amount of code you have to write.

    What do you mean you cant assign a name to the select tag? You should never assign a name to it, as struts uses the names for automatic form bean population from the request. Use id tags instead.

    e.g.
    <html:select property="selectedCountry" styleId="countryId" onchange="changeCountry();">
    <html:optionsCollection property="countryList" value="countryId" label="countryName" />
    </html:select>
    
    

    then use getElementById() to get the object instead


Advertisement