TRI0N Posted March 1, 2007 Share Posted March 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
TRI0N Posted March 1, 2007 Author Share Posted March 1, 2007 Also I forgot to mentions the numbers are to be multiplied by to get the sum... Drop Down 1: 6 Drop Down 2: 2 Total Number of Items: 12 Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 What's the problem here? Get the value of the two, multiply them, and put the result somewhere. Quote Link to comment Share on other sites More sharing options...
TRI0N Posted March 1, 2007 Author Share Posted March 1, 2007 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 Sure, on all counts: 1) You can write out the value into a SPAN anywhere on the page. 2) You can easily have an onload handler that calls the same function Quote Link to comment Share on other sites More sharing options...
TRI0N Posted March 2, 2007 Author Share Posted March 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
ozfred Posted March 2, 2007 Share Posted March 2, 2007 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? <URL: http://www.jibbering.com/faq/#FAQ4_15 > Quote Link to comment Share on other sites More sharing options...
TRI0N Posted March 2, 2007 Author Share Posted March 2, 2007 Hummm that link didn't even show me anythig to what was previously discussed. Anyone willing to give me some examples on getting this working? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 2, 2007 Share Posted March 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
TRI0N Posted March 3, 2007 Author Share Posted March 3, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.