PDA

View Full Version : passing form parameters to a javascript function


gymshoe
08-27-2001, 06:50 PM
I have a form that collects 2 things and sends it off to a another page that collects the info and does stuff with it. Something like this:
<form name="somename" method="post" action="mypage.php" target="new">
<input type="hidden" name="var1" value=1>
<input type="hidden" name="var2" value=2>
<input type="submit" value="Sent">
</form>

k....this all works fine and stuff.
my problem comes when i try to control the window that mypage.php opens up in. I wanted it to be a fixed size so i made javascript function called OpenPopup() that uses the window.open(...) function with mypage.php as the target page.

so the form declaration now looks like:
<form name="somename" method="post" action="javascript:OpenPopup()">

the problem is...now the form's parameters (var1 and var2) don't get passed through to mypage.php.

i can't seem to figure out how to pass the form's parameters through.
anyone have an idea?

thanks in advance!

-James

dank
08-27-2001, 07:22 PM
Well, to pass the values to a JavaScript function, you would do:

javascript:OpenPopup(var1, var2)

However, aren't the values of var1 and var2 being set at the receiving end, not the sending form? If so, then I don't see how you would pass not yet set variable values to the form's action...

Dan

gymshoe
08-27-2001, 08:10 PM
well.. let's say my form has the action = "mypage.php"
mypage.php will look for a certain number of variables, let's say var1, var2, var3

from the code sample above, var1 and var2 are already set. Let's say var3 is tied to something like:
<select name="var3">
<option value=1>One
<option value=2>Two
</select>

from what i understand...when i hit the submit button, it will send the values of var1, var2, var3 to mypage.php in its html header.

alrighty....the problem with this is i'm unable to control the window size that mypage.php opens up in. Thus I'm trying to use the window.open function. However, when I do that...I lose the ability for the submit button to pass the values of my variables through.

OOOR....i'm going about this all wrong?

-James

dank
08-27-2001, 08:18 PM
I must confess, I don't have a clue what the form example and your popup goal have to do with each other, so someone else might have to take a swing...

Dan

gymshoe
08-27-2001, 10:21 PM
Okay...i found a solution....thanks to cnn.com :)

the form declaration would be something like this:
<form method="post" action="mypage.php" target="mywindow">
...
...
...
<input type="submit" value="sent" onClick="OpenPopup()">
</form>

and the OpenPopup() function would be defined as follows
function OpenPopup()
{
bla = window.open('mypage.php','mywindow','height=500,width=500');
bla.focus();
}

Soooo.....the form has a target of mywindow, so mypage.php will open in the window called mywindow. The onClick event calls the javascript function OpenPopup which creates a window with height and width of 500 called mywindow. So the submit will send the data it gathers in the form to mypage.php into the window called mywindow with the right size! ...and THAT'S what i've been trying to do all DAY!
and **** it feels good to finally figure something out!
8}