Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto calculate dynamically created checkboxes in a form

Status
Not open for further replies.

Jay319

Technical User
Feb 21, 2003
16
US
Hi,

I have a form that has some dynamically created checkboxes ... <input name="bkZones" type="checkbox" id="bkZones" value="<%=(rsZones.Fields.Item("zZone").Value)%>"> . I also need to capture some "quantity values" from the database when they check the box that I would like to appear in a "Total Textbox" on the form.

The end result would be the zone information populating the zone field in my database and the calculated total of the zones picked populating the total field in my database.

I have seen a number of hard coded examples of this in Javascript, but none where the information is dynamically generated.

Thanks  for any help,

Jay
 
Hi,

I did come across some javascript in this forum which does a nice job of putting a total of the "Zones" checked into a "Total" textbox on my form ...

<script>
function calculate(){
ttl = 0
//sets the total couter to 0
allInput = document.getElementsByTagName("input")
//loads all INPUT elements into an array called "allInput"
for(x=0; x<allInput.length; x++){
//prepares to loop through the allInput array
if (allInput[x].type == "checkbox"){
//if the input type is a checkbox proceed
if (allInput[x].checked){
//if the checkbox is checked proceed
val = parseFloat(allInput[x].value)
//load the number value into a var called val
if (!isNaN(val)) ttl += val
//if val is a valid number (ie - not Not a Number) add it to the total
}
}
}
document.getElementById("bkTotal").value = ttl
//write the total to an input with the ID box4
}
</script>

-----------------------


Here are fom elements ...

<input type="checkbox" id="Checkbox126" name="Checkbox12" value=<%=(rsZones.Fields.Item("zQuantity").Value)%>
onClick="calculate(this.form)">
<%=(rsZones.Fields.Item("zZone").Value)%> <strong> </strong></div></td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsZones.MoveNext()
Wend
%></td>
</tr>
<tr>
<th class="WADADataTableHeader">Total:</th>
<td class="WADADataTableCell"><input type="text" name="bkTotal" id="bkTotal" value="" size="32" /></td>

----------------

When I submit the form I need it not only to send the "zQuantity" to my database, but also the "zZone" to the database.

Is there a way to not only perform the script and get my total, but also send the "zZone" value to the database when the checkbox is clicked? "zZone" is the name of the zone.

thanks, Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top