Jump to content

Form refresh and submit


Rostok

Recommended Posts

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 'tax' 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:

[pre]<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>[/pre]

Everything so far is working great, but I have a problem. In order for the page to reloaded (to update the changed value of the hidden field), the form has to post to itself, as I understand it.

[pre]<form name="checkoutform" action="" method="post" onsubmit="return validateCard(this.cardnumber.value,this.cardType.value,this.cardmonth.value,this.cardyear.value);">

[/pre]

But after the form is filled with customer information, when the submit button is pressed, all information in the form should be validated (I have credit card validation script and required fields validation script included) and then the form should be posted to other php page, for inserting the customer information into database and sending the confirmation e-mail.

[pre]<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;"/>[/pre]

My question is: How can I update the page/form and make some calculation when the dropdown list changes his value and at the same time to be able to submit the form to other php page?

 

Thanks,

Robert

 

Link to comment
https://forums.phpfreaks.com/topic/40175-form-refresh-and-submit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.