Search code examples
javascriptjspstrutsstruts-1

How to use Struts1 tag in JavaScript?


I need to display a form having flowing requirements.

  1. The first element is a drop down with four values.
  2. Based on the value selected from the first drop down ,I have to display either drop down or text filed (dynamically) as a second element.

My project is in Struts 1.1 and view is JSP. I have to use struts text filed and drop down. How do I achieve this?

<tr>
    <td width="50%">
        <bean:message key="edec.declaration.permit_detail_key" />
    </td>

    <td>
        <html:select property="permit_detail_key" onchange="permitDetail.alignControl();">
            <html:option value="">
                <bean:message key="prompt.selectone" />
            </html:option>
            <html:options filter="false" collection="<%=  option373_userName %>" property="code" labelProperty="<%=code_list_option%>" />
        </html:select>
    </td>
    <!--  <td width="50%" align="left"><input id="textboxstyle" type="text" name="permit_detail_key" size="30" maxlength="70"> </td> -->
</tr>

<logic:present name="<%= option374_userName %>" scope="application">
    <tr>
        <td width="50%">
            <bean:message key="edec.declaration.permit_detail_value" />
        </td>

        <td>
            <div id="temp">
                <html:select property="permit_detail_value">
                    <html:option value="">
                        <bean:message key="prompt.selectone" />
                    </html:option>
                    <html:options filter="false" collection="<%=  option374_userName %>" property="code" labelProperty="<%=code_list_option%>" />
                </html:select>
            </div>
        </td>
    </tr>
</logic:present>
permitDetail.alignControl = function() {
    var permit_detail_key_selected = document.forms[0].permit_detail_key.value;
    // alert(permit_detail_key_selected);

    if (permit_detail_key_selected == "1" || permit_detail_key_selected == "2") {
        document.getElementById("temp").innerHTML = ""
    } else {
        document.getElementById("temp").innerHTML = "";
    }
}

How to make these inner html as struts textbox or conmbobox?


Solution

  • There are two options: 1. Create two divs initially set the display:none style. On change of first drop down value, call a java script function and depending on value, make either div with style display:block. 2. If you do not want to do in java script, call ajax function and in struts action class, decide which div to be displayed.

    Hope this helps.