...

View Full Version : Help on Real time sales tax calculation



Aileen
07-09-2002, 11:12 PM
I would like a script that would calculate sales tax automatically (without pressing any 'calculate' button) when a user clicks on a checkbox for california resident. That script would add the sales tax to subtotal to generate Grand Total. Thank you.

ConfusedOfLife
07-09-2002, 11:25 PM
Well, if you don't wana have a button, one way is to check if your check box is checked by a recursive function that is run in body tag. I have something that does the similar concept below:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
flag = "U";
before = after = 0;
function dosth()
{
if ( flag == "U" )
document.nothing.AText.value = document.nothing.AText.value.toUpperCase();
else
document.nothing.AText.value = document.nothing.AText.value.toLowerCase();
}
function repeating()
{
after = document.nothing.AText.value.length;
if ( after != before )
dosth();
window.setTimeout("repeating()", 100);
}
</script>
</head>

<body onload="repeating()">
<form name="nothing">
<input type="Text" size="40" name="AText">
<input type="Reset">
<br>
<input type="Radio" name="case" onclick="flag = 'U';" checked> Upper Case
<input type="Radio" name="case" onclick="flag = 'L';"> Lower Case
</form>


</body>
</html>


In each .1 second it checks which of the radio buttons are selected, then it converts the text based on their value ( If uppercase, everything would be wirtten in uppercase & vice versa). The repeating() function that's our background recursive function is working fine and checking those two radio buttons, I think you can change the code to fit your situation!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum