Click to See Complete Forum and Search --> : dynamic table values


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>

HWinMT
10-01-2003, 03:13 PM
Does anyone know why the envelope icon for this thread has a black hole in the middle of it?

HWinMT
10-01-2003, 07:16 PM
Below is html for a table row. The input.type.chkBox names have a prefix + a row number (1,2,3,4) suffix. Each of the input.type.text names have a prefix name and a matching row number for the row.

I want to pass the row number to a js function in the onchange event.

I then want to change the value of the input.type.text values when the checkbox on the same row is checked, by concatenating the the row number passed in the onchange event to the known name prefixs of the text boxes. But I haven't had any luck making it work.

B.T.W. - I'd still like to know what the black hole in this threads icon means. It's not in the legend at the bottom of the page.

<script type="text/javascript">
//put 0.00 in row values when a chkBox.checked
//r = value passed in onchange event
//ipList is the name of the form
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>

<tr>
<td><input type="checkbox" name="prog1" onchange="java script:initRowValues(1)" /></td>
<td><input type="text" name="priceUnit1" /></td>
<td><input type="text" name="authUnits1" /></td>
</tr>

HWinMT
10-02-2003, 10:18 AM
I'm sure that out of the 48 viewings at least 46 got a good laugh. Sometimes no matter how many times you look at the same broken code it still looks like it ought to work.

This accomplishes my task and provides a mechanism for additional client side validation.

<script type="text/javascript">
//<![CDATA[
//put 0.00 in row values when a program is selected
function initRowValues(r) {
var chkBoxName = document.getElementById("prog" + r);
var priceVal = document.getElementById("priceUnit" + r);
var authuVal = document.getElementById("authUnits" + r);
if (chkBoxName.checked) {
priceVal.value = "0.00";
authuVal.value = "0.00";
}
else {
priceVal.value = "";
authuVal.value = "";
}
}
//]]>
</script>