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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript & ASP Variables 1

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
GB
I have been using code supplied by MVP's to caculate the total value of checkboxes "ttl" when checked but I now need to add to this another box which adds together this total "ttl" and another variable from my ASP code can this be done in say "document.getElementById("box5").value = ttl + <%ASPVariable%>"



<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
//write the total to an input with the ID box4
}
</script>
 

Yes - that should work just fine.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Thanks for the reply BillyRayPreachersSon

I tried all the permutations I could think of but didn't get the answer I expected. By adding, after the line document.getElementById("box4").value = ttl

Code:
document.getElementById("box5").value = <%PricesRs("BasicTotal")%>
Resulted in : Nothing displayed in either text box

Code:
document.getElementById("box5").value = ttl + <%PricesRs("BasicTotal")%>
Resulted in : Nothing displayed in either text box


Code:
document.getElementById("box5").value = ttl
Resulted in : the checkboxes total only displayed in both text boxes as you'd expect.

 

What does this:

Code:
<%PricesRs("BasicTotal")%>

equate to client-side?

It needs to be a valid number for you to be able to add it.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
and anyway - shouldn't it be:

Code:
<%[COLOR=red][b]=[/b][/color]PricesRs("BasicTotal")%>

?

Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Thanks BillyRayPreachersSon

The "=" was the thing that swung it, I had omitted it from the syntax. As you can tell I'm new to this coding lark.

Can you please tell me how I can format the values to appear in the text boxes into say "#,###.##" or even currency values.

 
Yes I did search initially for the combination of asp & javascript variables but didn't find the answer to my problem which BillyRayPreachersSon solved for me. Knowing the best place to search is often troublesome too.

You may have forgotten what it was like when you started out but this is a pain combining ASP, Javascript HTML etc to achieve what you want. My question was in addition to my original post to save me searching further.

Thanks for the link anyway Lee.

And a thankx to BillyRayPreachersSon for your help too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top