Jump to content

[SOLVED] Calculate 2 Values Live.


TRI0N

Recommended Posts

Doing the work in PHP but what a JS that will take 2 values that will calculate and display that sum.

 

Would be nice to show the sum with a simple php echo.  But if not then anything will work.

 

Tried to search for this but came up with no answer on the fourms.

 

The 2 numbers are from 2 drop downs and would like the sum to be places where XX is in the example below.

 

Total Number of Items: XX

Link to comment
Share on other sites

The problem I'm having now is that I have a form but the script I found that somewhat does what I want only shows the Refreshing Total in a Input box and not sure how to make it show its just text on the screen.

 

Like:

Your Total Is: XX

 

Not:

Your Total Is: [XX] (not inside a input box....  Can this be done?

 

<script type="text/javascript"> 
function addMe(){ 
v1=document.getElementById("val1").value 
v2=document.getElementById("val2").value 

v3=Number(v1)*Number(v2) 

document.getElementById("tot").value=v3 

} 
</script>

 

Also is there a way that I can add this to the body tag so that it takes the 2 current values and adds them on page load?

 

Link to comment
Share on other sites

Not to sound dead in the wind but can you give me an example of using SPAN and a onload handle that would do that please?

 

The point is I'm at loss getting this to work and would be great to get some example input...

 

SPAN for tot

 

and

 

onLoad for addMe.

 

 

Thanks a ton.

Link to comment
Share on other sites

Your Total Is: <SPAN id="tot"></SPAN>

 

<script type="text/javascript"> 
function addMe(){ 
v1=document.getElementById("val1").value 
v2=document.getElementById("val2").value 

v3=Number(v1)*Number(v2) 

document.getElementById("tot").innerHTML=v3 

} 
</script>

 

Of course, you can just call this function from the onload.

Link to comment
Share on other sites

Thanks for the fix and the onLoad was simple thought it would be something differnt that what you normally do with onLoad rather then just <body onLoad="addMe()">.  Thought it would be some wacky thing or another..  But again thanks for the fix it works great!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.