HWinMT
10-01-2003, 12:10 PM
JSP page: form named ipList
Some clues why this isn't working. I'm trying to pass a row value as a string to a js function that will initialize other text boxes to "0.00" by concatenating the row value to a base input name.
<script type="text/javascript">
//<![CDATA[
//put 0.00 in row values when a program is selected
function initRowValues(r) {
var chkBoxName = "prog" + r;
var priceVal = "priceUnit" + r;
var authuVal = "authUnits" + r;
if (document.ipList.chkBoxName.checked) {
document.ipList.priceVal.value = "0.00";
document.ipList.authuVal.value = "0.00";
}
else {
document.ipList.priceVal.value = "";
document.ipList.authuVal.value = "";
}
}
//]]>
</script>
Form with table generated from database
<%int iTblRow = 0; //count table rows not including header%>
while(rs.next()) {
sProg = rs.getString("program");
sProgID = rs.getString("progID");
int iIPnum = rs.getInt("ipNum");
sIPnum = String.valueOf(iIPnum);%>
<tr>
<td><input type="checkbox" id="prog" name="<%="prog" + ++iTblRow%>" tabindex="<%=++tbi%>" value="<%=sIPnum%>" onchange="javascript:initRowValues(<%=String.valueOf(iTblRow)%>)" /><%=sProg%></td>
<td><%=sProgID%></td>
<!--max unit cost = $99999.99 or $99999999-->
<td align="center"><input type="text" id="priceUnit" name="<%="priceUnit" + iTblRow%>" tabindex="<%=++tbi%>" size="8" maxlength="8" class="inputNoBox" /></td>
<!--max authorized units = 999.99 or 999999-->
<td align="center"><input type="text" id="authUnits" name="<%="authUnits" + iTblRow%>" tabindex="<%=++tbi%>" size="6" maxlength="6" class="inputNoBox" /></td>
</tr>
}
Sample source output:
<tr>
<td><input type="checkbox" id="prog" name="prog1" tabindex="2" value="7" onchange="javascript:initRowValues(1)" />Case Management</td>
<td>B2022</td>
<td align="center"><input type="text" id="priceUnit" name="priceUnit1" tabindex="3" size="8" maxlength="8" class="inputNoBox" /></td>
<td align="center"><input type="text" id="authUnits" name="authUnits1" tabindex="4" size="6" maxlength="6" class="inputNoBox" /></td>
</tr>
Some clues why this isn't working. I'm trying to pass a row value as a string to a js function that will initialize other text boxes to "0.00" by concatenating the row value to a base input name.
<script type="text/javascript">
//<![CDATA[
//put 0.00 in row values when a program is selected
function initRowValues(r) {
var chkBoxName = "prog" + r;
var priceVal = "priceUnit" + r;
var authuVal = "authUnits" + r;
if (document.ipList.chkBoxName.checked) {
document.ipList.priceVal.value = "0.00";
document.ipList.authuVal.value = "0.00";
}
else {
document.ipList.priceVal.value = "";
document.ipList.authuVal.value = "";
}
}
//]]>
</script>
Form with table generated from database
<%int iTblRow = 0; //count table rows not including header%>
while(rs.next()) {
sProg = rs.getString("program");
sProgID = rs.getString("progID");
int iIPnum = rs.getInt("ipNum");
sIPnum = String.valueOf(iIPnum);%>
<tr>
<td><input type="checkbox" id="prog" name="<%="prog" + ++iTblRow%>" tabindex="<%=++tbi%>" value="<%=sIPnum%>" onchange="javascript:initRowValues(<%=String.valueOf(iTblRow)%>)" /><%=sProg%></td>
<td><%=sProgID%></td>
<!--max unit cost = $99999.99 or $99999999-->
<td align="center"><input type="text" id="priceUnit" name="<%="priceUnit" + iTblRow%>" tabindex="<%=++tbi%>" size="8" maxlength="8" class="inputNoBox" /></td>
<!--max authorized units = 999.99 or 999999-->
<td align="center"><input type="text" id="authUnits" name="<%="authUnits" + iTblRow%>" tabindex="<%=++tbi%>" size="6" maxlength="6" class="inputNoBox" /></td>
</tr>
}
Sample source output:
<tr>
<td><input type="checkbox" id="prog" name="prog1" tabindex="2" value="7" onchange="javascript:initRowValues(1)" />Case Management</td>
<td>B2022</td>
<td align="center"><input type="text" id="priceUnit" name="priceUnit1" tabindex="3" size="8" maxlength="8" class="inputNoBox" /></td>
<td align="center"><input type="text" id="authUnits" name="authUnits1" tabindex="4" size="6" maxlength="6" class="inputNoBox" /></td>
</tr>