OZONE Asylum
Forums
DHTML/Javascript
JS Function & Variable Storage
This page's ID:
27926
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hi, I am trying to input a variable (hours) from the input text box and on clicking submit, execute the function, and display the result in a textbox. There is a calculated value current_charges and an accumulated value running_total. Everytime a value is input and the person clicks calculate, I want the current_charges to be output to the textarea named "current" and running_total to be output to the textarea named "running_total". I am having two problems: a) The values are put into the textarea and then immediately removed because the page refreshes (reason unknown...the address extension then includes parameters) b) the running_total variable is cleared everytime the person clicks calculate. I believe this is because the page gets refreshed on clicking calculate so the previous value is lost. I have put in an alert in the function so there is time to see what happens. [code] <html> <head> <title>Test</title> </head> <script language="javascript" type="text/javascript"> var current_charges=0; var running_total=0; var hours; function calculateCharges(hours) { if ( hours <= 3 ) { current_charges = 2; } else if ( hours > 3 && hours <= 19) { current_charges = 2 + (0.50 * (hours - 3)); } else { current_charges = 10; } document.parking.current.value=current_charges; running_total=running_total + current_charges; document.parking.running.value=running_total; [b]alert("current_charges:" + current_charges + " running_total: " + running_total);[/b] return false; } </script> <body> <form name="parking" method="get" onSubmit="calculateCharges(document.parking.hoursparked.value)"> Please enter the number of hours parked for the current customer: <br> <input type="Integer" name="hoursparked" value=""> <br> <input type="Submit" value="Calculate"> <p> Charges for current customer: <textarea name="current" rows="5" cols="5" value=""> </textarea> <p> Accumulated charges: <textarea name="running" rows="5" cols="5" value=""> </textarea> </form> </body> </html> [/code] Any help would be greatly appreciated.
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »