Change formtarget.php

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
phpretard
Forum Commoner
Posts: 26
Joined: Wed Aug 01, 2007 8:03 pm
Location: Orlando Florida

Change formtarget.php

Post by phpretard »

Is it possible to change the target of a form with a select box?

Example:

<form action="target1.php" OR "target2.php" method="post">

<select name="league" size="1">
<option value="target1">target1</option>
<option value="target2">target2</option>
</select>

</form>

I know this code doesn't make sences but I hope it illistrates my question.
User avatar
robshanks
Forum Commoner
Posts: 32
Joined: Sun Aug 05, 2007 9:27 pm
Location: Hull, UK

Post by robshanks »

Not sure using pure php you can do it . . . other than by having a target.php file which evaluates the option box and passes the data to the correct page target1.php or target2.php.

With javascript you can do it easily by evaluating the option box then directing the data to the correct php file.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

With Javascript:

Untested

Code: Select all

set_target() {
     var target = document.getElementById('selecttarget');
     var select_it = document.getElementById('league');
     target.form.action = select_it.value;
}
 

Code: Select all

<form action="" method="post" id="selecttarget" onchange="set_target();">

<select id="league" size="1">
<option value="target1.php">target1</option>
<option value="target2.php">target2</option>
</select>
</form>
phpretard
Forum Commoner
Posts: 26
Joined: Wed Aug 01, 2007 8:03 pm
Location: Orlando Florida

Post by phpretard »

that worked pretty good for not testing it!

Thanks

-Anthony
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

AFAIR there is a problem in Opera browser about writing to "action" property. Not sure about it - check :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply