hi,
I have a question on how to pass varibales from a form to javascript functions within a for loop in jsp. I have the code below and I want to perform the following. In the beginning, all check boxes are disabled. When the user choose somthing in the select menu, the check boxes are enabled. Then when Check01 is checked and Check02 will be checked as well.
<script language=”javascript”>
function selected(prop) {
for (i=0; i<2; i++)
prop[i].disabled = false;
}
function checked(prop) {
if (prop[0].checked)
prop[1].checked = true;
}
</script>
<form action=”test_action.jsp” method=”post” name=”table”>
<% for (int i=0; i<3; i++) { %>
<select name=”fieldtype<%=i%>” size=1 onChange=”selected(??)”>
<option></option>
<option value=”1″>Option1</option>
<option value=”2″>Option2</option>
</select><br>
<input type=”checkbox” name=”prop<%=i%>” value=”c1″ onClick=”checked(??)” disabled />
Check01<br>
<input type=”checkbox” name=”prop<%=i%>” value=”c2″ disabled/>
Check02<br>
<% } %>
</form>
I try the following methods but not work:
(1)
onChange=”selected(this.form.prop'<%=i%>’)” and onClick=”checked(this.form.prop'<%=i%>’)”
(2)
onChange=”selected(‘this.form.prop<%=i%>’)” and onClick=”checked(‘this.form.prop<%=i%>’)”
(3)
String prop = “this.form.prop” + i; //within the for loop
onChange=”selected(‘<%=prop%>’)” and onClick=”checked(‘<%=prop%>’)”
Please help!
thx very much
ypc