Click to See Complete Forum and Search --> : (help) want radiobutton to determine form action


fh03
June 6th, 2004, 05:16 AM
alright I'm writing form which calls out a function F1 onsubmit

but I want it to do that based on what the user answers to the last question on the form

this question has a yes/no answer, if the answer is yes, I want it to call F1 as it would and the function basically sends the form contents to two different places, if the answer was no, I want it to just submit it to one place...

now here's how I've implemented this...




FORM method="POST" action="form.php" onsubmit="submitit(this)">
echo "<input name='smoke' type='radio' value='No' onClick='smoker('NO')'>";
echo "No";
echo "<input type='radio' name='smoke' value='Yes' onClick='smoker('YES')'>";
echo "Yes";

function smoker($sm1)
{
$smoke = $sm1;
if ($smoke == 'YES')
{
echo "<script type='text/javascript'>";
echo "function submitit(fh)";
//below line would submit to two places
echo "{ fh.submit(); fh.target='_blank' fh.action='form2.php';";
echo "fh.submit(); return false; }</script>";
}
else //just submit to one place
{
echo "<script type='text/javascript'> function submitit(fh) { fh.submit(); return false; }</script>";
}
}
echo "<INPUT type='submit' value='Click me!'>";



but this does not do what I want it to do... it just always submits to the 1st form... and nothing else, I've been tweeking around for quite a while, was wondering if anyone can tell me what I'm doing wrong, or perhaps provide a better solution to my problem?

thank you

PallaviDalvi
June 9th, 2004, 10:26 AM
i tried this piece of code and it submitted to two places.

<body>
<form name=frm method=post action=place1.php>
<input type=radio name=rd value=yes>Yes
<input type=radio name=rd value=no>No
<input type=button value=submit onclick="sub_frm();">
</form>
</body>

<script language=javascript>
function sub_frm()
{
if (document.all.item("rd")[0].checked )
{
//submits to place1.php
frm.submit();

frm.target='_blank'
frm.action='place2.php';

//submits to place2.php
frm.submit();
}
if (document.all.item("rd")[1].checked)
{
//submits to place1.php
frm.submit();
}
}
</script>
am not sure if this code does what u wanted. Nevertheless i tried out something i'd never tried before... Thanx!