Page 1 of 1
Change formtarget.php
Posted: Tue Aug 07, 2007 2:08 pm
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.
Posted: Tue Aug 07, 2007 2:31 pm
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.
Posted: Tue Aug 07, 2007 5:48 pm
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>
Posted: Tue Aug 07, 2007 6:16 pm
by phpretard
that worked pretty good for not testing it!
Thanks
-Anthony
Posted: Tue Aug 07, 2007 7:02 pm
by VladSun
AFAIR there is a problem in Opera browser about writing to "action" property. Not sure about it - check
