I have posted this onto the Javascript forum but havent as yet received any help so as it involves both ASP and javascript I thought I'd add it here. So here goes....
Within my ASP pages I have been using javascript code supplied by Tek-Tips MVP's to caculate the total value of checkboxes "ttl" when checked, put this into text box4 and this worked fine, but I now need to add to this another box, "textbox5" which adds together this javascript total "ttl" and another variable from my ASP code. Firstly can this be done ? secondly I tried to do the following without success.
<script>
function calculate(inObj){
//Don't need to pass inObj here since it is not used in the function
ttl = 0
grandttl = 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("box4").value = ttl
document.getElementById("box5").value = ttl + <%ASPvariable%>
//write the total to an input with the ID box4
}
</script>
Within my ASP pages I have been using javascript code supplied by Tek-Tips MVP's to caculate the total value of checkboxes "ttl" when checked, put this into text box4 and this worked fine, but I now need to add to this another box, "textbox5" which adds together this javascript total "ttl" and another variable from my ASP code. Firstly can this be done ? secondly I tried to do the following without success.
<script>
function calculate(inObj){
//Don't need to pass inObj here since it is not used in the function
ttl = 0
grandttl = 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("box4").value = ttl
document.getElementById("box5").value = ttl + <%ASPvariable%>
//write the total to an input with the ID box4
}
</script>