Link to home
Start Free TrialLog in
Avatar of kuclu
kuclu

asked on

make form ACTION a variable

I have a multipage form, where the user progresses from one page to another in a prefixed order. Now i want to give the user the option to choose where he wants to proceed, i.e. I am trying to make the value of the <FORM ACTION =""> elements to be different.

Example:

If user selects "GO to form A" from a pulldown menu,
          then <FORM ACTION="formA.php">
If user selects "GO to form B" from a pulldown menu,
          then <FORM ACTION="formB.php">

Is this possible?

This is what my multipage form looks like. I have a fieldforwarder so that choices selected are 'memorized' from one page to another, until the final page is submitted to a database...

=================================================================
<?php  
    include ('fieldforwarder.php');
?>

<html>
<HEAD></HEAD>
<BODY>

<FORM method="post" action="form2.php" name="form1">
     
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a">A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b">B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c">C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d">D</td>

<?php echo field_forwarder(); ?>

<p><input type="submit" name="submit2" value="Proceed >>">
</FORM>
     
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
Avatar of ncoo
ncoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
put this on the combobox or whatever object you are using for the user to select:

onchange="form1.action=this.options[this.selectedIndex].value;"

if you are using checkboxes just use the onClick event:

onClick="form1.action='a';" and so on...
Avatar of gamebits
What I would do is send the user to the next page and there you use a switch statement to display the form he selected in the first place.

switch($form)
        {
        case 'a':

                    display form a

      break;

        case 'b':

                     display form b

       break;

}


and so on
Avatar of ncoo
ncoo

Using your code if you click a checkbox it will use that as the action:

<html>
<head>
<script language="JavaScript">
<!--//
function changeAction(yourvalue) {
      var myform = document.getElementById('myform');
      myform.action=yourvalue;//myfield.value;
}

//--></script>
</head>
<body>

<FORM method="post" id="myform" action="form2.php" name="form1">
     
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a" onclick="changeAction('cb1');">A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b" onclick="changeAction('cb2');">B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c" onclick="changeAction('cb3');">C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d" onclick="changeAction('cb4');">D</td>


<p><input type="submit" name="submit2" value="Proceed">
</FORM>

</body>
</html>
Copy and paste code below.

if you select a from the select box you go to forma.php
if you select b from the select box you go to formb.php


<html>
<head>
<script language="JavaScript">
<!--//
function changeAction() {
      var myform = document.getElementById('myform');
      var myfield = document.getElementById('myfield');

      myform.action='form'+myfield.value+'.php';
}

//--></script>
</head>
<body>

<FORM method="post" id="myform" action="form2.php" name="form1">
<select id="myfield" onchange="changeAction();">
<option value="a">Go A</option>
<option value="b">Go B</option>
</select>    
<INPUT TYPE="checkbox" NAME="cb1" VALUE="a" >A</td>
<INPUT TYPE="checkbox" NAME="cb2" VALUE="b" >B</td>
<INPUT TYPE="checkbox" NAME="cb3" VALUE="c" >C</td>
<INPUT TYPE="checkbox" NAME="cb4" VALUE="d" >D</td>


<p><input type="submit" name="submit2" value="Proceed">
</FORM>

</body>
</html>