Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I have a PHP page with submission form for collectiong billing information from the customer. When the customer selects his state of residence from a dropdown list, the page is refreshed and some tax calculation as performed. I’m using the “onChange” event for dropdown list to call a JavaScript, which then checks which state is selected, updates a value for a hidden field in the form and reloads the page. The value of this hidden field is then used by php code in the form to calculate the tax.
Here is JavaScript code:
[syntax="html"]<script type='text/javascript'>
function calculateTax()
{
state = document.forms['checkoutform'].elements['billstate'];
var stateVal = state.options[state.selectedIndex].value;
if(stateVal == 'VT')
{
document.forms['checkoutform'].elements['tax'].value = 0.07;
}
document.forms['checkoutform'].submit();
}
</script>form has to post to itself, as I understand it.
Code: Select all
<form name="checkoutform" action="" method="post" onsubmit="return validateCard(this.cardnumber.value,this.cardType.value,this.cardmonth.value,this.cardyear.value);">
Code: Select all
<form name="checkoutform" action="confirmorder.php" method="post" onsubmit="return validateCard(this.cardnumber.value,this.cardType.value,this.cardmonth.value,this.cardyear.value);">
.
.
.
<input type="submit" value="Make Purchase" onClick="MM_validateForm('namefull','','R','email','','RisEmail','phonework','','R','billaddress1','','R','billcity','','R','billzip','','R');return document.MM_returnValue;"/>Thanks,
Robert
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]