disable a sellect input based on another select input in jsp page using javascript – Education Career Blog

i have two select input fields in a jsp page. i want to disable the second input based on the value of first input. i wrote the function. but it is not working, plz help.

function selectTimePeriod()
{

var rtype = document.getElementById('customer.customerType').value;
var corporateSize = document.getElementById("customer.corporateSize").value;

if(rtype == "PRS" )
  {
   document.getElementById("corporateClient").style.display = 'none';    
   document.getElementById("prjClient").style.display = 'none';    

   document.getElementById("prsClient").style.display = '';
   corporateSize.disabled=true;
  }

}

the input fields are:

            <td>
            <html:select property="customer.customerType" styleId="customer.customerType" onchange="selectTimePeriod()">
                <%
                    for (index6 = 0; index6 < Constants.customerTypeConstants.length; index6++)
                    {
                %>
                        <html:option value="<%=Constants.customerTypeConstantsindex60%>"><%=Constants.customerTypeConstantsindex61%></html:option>
                <%        
                    }
                %>
            </html:select>
        </td>

    </tr>

    <tr >
    <td><label class="desc"><bean:message key="label.customer.corporateSize"/></label></td>
        <td>
            <html:select property="customer.corporateSize" styleId="customer.corporateSize">
                <%
                    for (index6 = 0; index6 < Constants.corporateSizeConstants.length; index6++)
                    {
                %>
                        <html:option value="<%=Constants.corporateSizeConstantsindex60%>"><%=Constants.corporateSizeConstantsindex61%></html:option>
                <%        
                    }
                %>
            </html:select>
        </td>

,

what is the id for your 2nd drop down? try this statement

document.getElementById('<id of 2nd dropwon>').disabled = 'true';    

Leave a Comment