PDA

View Full Version : Two possble form submissions based on variable.


ip23
08-28-2002, 03:46 PM
Hi I have been trying to write a simple function that will go to a certain page depending on the checkbox that someone clicks. At the moment it just submits to itself.

The function
==============
function pForm() {
page = document.login.page.value
if (page == "newuser") {
document.login.action = "newUser.asp";
document.login.submit();
}
else if (page == "returning") {
document.login.action = "userInfo.asp";
document.login.submit();
}
}

The form
==============
<form action="javascript:pForm();" method="post" name="login">
<input type="radio" name="page" value="newuser" checked>
<input type="radio" name="page" value="returning">
<input type="submit" value="Sign In">

Any help would be appreciated!

requestcode
08-28-2002, 03:58 PM
Instead of perform the function from the action field try using the onSubmit event like this:
<form action="" method="post" name="login" onSubmit="pForm()">

ip23
08-28-2002, 04:12 PM
It still seems to submit to itself, as soon as I add something in the action it goes to that page.

requestcode
08-28-2002, 04:46 PM
I think your problem is that you are not specifying which radio button value to use. Try doing this:
if(document.login.page[0].checked)
{page==document.login.page[0].value}
else
{page==document.login.page[1].value}

That would replace the one line where you grab the value. You could also try rewriting the function to this:
function pForm() {
if (document.login.page[0].checked)
{
document.login.action = "newUser.asp";
document.login.submit();
}
else
{
document.login.action = "userInfo.asp";
document.login.submit();
}
}

ip23
08-28-2002, 05:04 PM
Thank you so much requestcode, I got it working now.