php variables in javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

php variables in javascript

Post by shiznatix »

i am trying to open a new window on hitting submit but with passing variables with the form that has the submit button. i believe this would consist of javascipt with some php maybe but how would i submit the varialbes in the form with the outside javascript. here is the code i have now.

Code: Select all

<SCRIPT LANGUAGE=&quote;javascript&quote;>
<!--
window.open ('view_cart.php?action.php?action=add_item', 'newwindow', config='height=100,
width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,
location=no, directories=no, status=no')
-->
</SCRIPT>

<form action=&quote;view_cart.php?action=add_item&quote; method=&quote;post&quote;>
<img src=&quote;img/Stencils/mazdaspeedstencils.jpg&quote; width=&quote;491&quote; height=&quote;45&quote;><br>
Price: $2.50<br>
<input type=&quote;hidden&quote; name=&quote;itemName&quote; value=&quote;MazdaSpeed Caliper Decal/Stencil&quote;>
<input type=&quote;hidden&quote; name=&quote;itemPrice&quote; value=&quote;2.50&quote;>
<input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;Add To Cart&quote; onClick=&quote;window.open();&quote;>
</form>
but this dosnt work.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can...
  1. iterate through the form on submission request creating a url with get data, then call the popup.
  2. generate the popup on submission, then pass the data to a waiting script on that page.
  3. choose to not use a popup ;)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

a. (no idea how to do that)
b. (how would i make the popup come up before i passed the data)
c. (not a option :D )

im confused as to how to do these things
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well..
  1. the code you posted thus far will immediately try to create a popup...
  2. open() returns a window object. You can send data through it..
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ahhh thanks feyd i got it. if anyone has the same problem open a blank window with
onclick="window.open('', 'windowName');" then have the form target as windowName
Post Reply