Javascript problem...

Any problem with javascript can be discussed here.
Post Reply
dexter
Posts: 32
Joined: Fri Mar 09, 2007 1:18 pm

Javascript problem...

Post by dexter »

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:

Code: Select all

<script type='text/javascript'>
function calculateTax()
{
	state = ****.forms['checkoutform'].elements['billstate'];
	var stateVal = state.options[state.selectedIndex].value;
	if(stateVal == 'VT')
	{
		****.forms['checkoutform'].elements['tax'].value = 0.07;
	}
	****.forms['checkoutform'].submit();
}
</script>
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.

Code: Select all

<form name="checkoutform" action="" method="post" onsubmit="return validateCard(this.cardnumber.value,this.cardType.value,this.cardmonth.value,this.cardyear.value);">
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.

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" ****="MM_validateForm('namefull','','R','email','','RisEmail','phonework','','R','billaddress1','','R','billcity','','R','billzip','','R');return ****.MM_returnValue;"/>

Questions:
  1. How can I refresh 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?
  2. How to return the changed value of the hidden field from JavaScript, so the php code knows that some state is selected from the dropdown list and that it should run the tax calculation accordingly? And if this can be done without refreshing the page (or posting the form), my problem is solved. Thanks...


Gyanu
Posts: 338
Joined: Mon Jul 30, 2007 2:03 pm
Contact:

Post by Gyanu »

it's very large

there may be the short way?
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

To change a hidden field value withour page reload you can use:

Code: Select all

****.form1.hidden_field.value="meaning";
or

Code: Select all

****.getElementById("hidden_id").value="meaning";
here is a simple form as example

[HTML]
<form name="form1"......>
<input type="text"...>
...
<input type="hidden" name="hidden_field" id="hidden_id" value="">
</form>
[/HTML]
Image
Gebbo
Posts: 554
Joined: Tue May 16, 2006 3:22 pm

javascript problem

Post by Gebbo »

hmm... looks interesting..
.............................:: Spirit of Fire ::..................................

Image
Tails5
Posts: 1302
Joined: Wed Mar 15, 2006 8:09 am
Contact:

Post by Tails5 »

You could create a PHP Session and insert the value into that, and destroy the session when the user finishes calculation.
Webmaster Yoda: You must confront the cPanel. Then, and only then, a webmaster will you be.
Julius Caesar: Veni, vidi, posti
icopsistonync
Posts: 9
Joined: Sat May 29, 2010 2:56 am
Contact:

Javascript problem

Post by icopsistonync »

Chanchal wrote:
> Hi,
>
> Any one knows about any java script function which capture the content
> of the browser window as image?
>
> Thanks
>
> Chanchal

It can be done in IE via an ActiveX control. Not only can it snapshot
the browser window, it can do the whole desktop.

But in JavaScript, no.
Gilbertwep
Posts: 5
Joined: Sat Nov 27, 2021 12:37 pm

-

Post by Gilbertwep »

The excellent and duly message.
Create
Post Reply