Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update php variable using javascript

Status
Not open for further replies.

bezierstek

Programmer
Aug 30, 2007
43
FR
Hi, (I did post this in the php forum thinking of using AJAX but it was pointed out it should be able to be done using just javascript hence my post here).

I need to change the subtotal on a page when two different things are changed. A php variable needs to be updated.

First is a dropdown where the user picks a number and the second is a checkbox when the user picks an advert type (2choices).

I am thinking javascript but don't particularly know where to start (not got good javascript skills at all).

Any help gratefully received to get me going.
 
A PHP variable cannot be changed from Javascript. Once a PHP script has run and delivered the page, it's life ends.

You could use javascript on the delivered HTML page to handle the price update, but that will only show text on the browser. If you want to get the updated detail back to a PHP script (so you can store it in a database for future reference), then you could do so by submitting a form (this can be done via AJAX or by a regular form submit button).

Hope this helps,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
To be honest (and having thought about it too), it is isn't particularly important to change the php variable as long as the correct price is displayed. The script will need to do some work after the form is submitted anyway and the final cost can be reworked out again using results from this working out. Really as long as the price is displayed that should be fine.

Still none the wiser on how to do it as my javascript is pretty appalling . I know I will have to pass the current subtotal from php to javascript then do the maths depending on the choices made on the form then display the new prices.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top