0

I have a form which has a text box and a drop down box. The value selected in the drop down is obtained from another java program which changes from time to time. User can change the value of the drop down for editing purposes. Now what I want is to make the text box enabled/disabled, depending upon the value that coming as selected in the drop down. The code is here.

<input type="text" size="3" name="length<%=f.getId()%>" value="<%=f.getLength()%>"   disabled="disabled"/>

<div class="type">
<select name="type<%=f.getId()%>" id="field_type">
<%
for(Field.FieldType t : Field.FieldType.values()){
%>
<option value="<%=t.name()%>" <%=(t.equals(f.getFieldType())) ? "SELECTED" : "" %>>    <%=t.name() %></option>
            <% } %>
</select></div>        
Som Sarkar
  • 289
  • 1
  • 5
  • 24

1 Answers1

0

You can just use some JavaScript for this. Here's an example assuming that you would like to enable it when the option with the value someValue has been selected.

<select ... onchange="if (value == 'someValue') form['length<%=f.getId()%>'].disabled = false">

Unrelated to the concrete problem, please note that this oldschool style of writing JSP is strongly discouraged since a decade. It's namely terribly unmaintainable. See also How to avoid Java code in JSP files?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555