We help IT Professionals succeed at work.

make form ACTION a variable

kuclu
kuclu asked
on
991 Views
Last Modified: 2008-04-24
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>
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
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...
CERTIFIED EXPERT

Commented:
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

Commented:
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>

Commented:
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>
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.