Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio button , Submit form 2

Status
Not open for further replies.

jhoann

Programmer
Apr 18, 2002
81
PH
hi

how i can 'code' this in HTML ?

I have 2 radio buttons and 1 submit button :

- cash
- cheque

submit button

my problem is there's only one action can be performed, but what I want is :
- when I check CASH and press SUBMIT button , I will go to FORM_CASH.HTML and when I check CHEQUE and press SUBMIT button , I will go to FORM_CHEQUE.HTML.

HOW I CAN DO THIS... PLEASE HELP , PLEASE


THANKS A LOT!
 
I know that this isn't exactly what you're looking for, but this one will redirect you to whichever location you chose as soon as you check the button. You could probably use a javascript function and an if statement and add that to the onClick property of the submit button. Not exactly what you need... but it's a start!!!

Code:
<INPUT type=&quot;radio&quot; name=&quot;location&quot; value=&quot;tek-tips&quot; onFocus=&quot;document.location.href='[URL unfurl="true"]http://www.tek-tips.com';&quot;>Cheque<BR>[/URL]
<INPUT type=&quot;radio&quot; name=&quot;location&quot; value=&quot;hotmail&quot; onFocus=&quot;document.location.href='[URL unfurl="true"]http://www.hotmail.com';&quot;>Credit[/URL] Card<BR>
<INPUT type=&quot;reset&quot;>
 
It's very simple:
[tt]
<script>
function changeAction(f)
{
if (f.payment[0].checked)
{
f.action = &quot;form_cash.html&quot;;
f.submit;
}
else
{
f.action = &quot;form_cheque.html&quot;;
f.submit;
}
}
</script>
[/tt]
then in html:

<form onsubmit=&quot;changeAction(this)&quot;>
<input type=radio name=payment value=cash>cash<br>
<input type=radio name=payment value=cheque>cheque
<br><input type=submit>
</form>

 
starway, I have to say that looks pretty nifty, but I have no idea how any of it works!!! Could you explain, if you wouldn't mind?

[wavey]
 
Each form has an &quot;action&quot; property that specify the target page with a script that process a form being sent. You can modify it according your needs before you submit a form, and this is what I did.
If the first radio is selected (payment[0].checked = true), then the action page should be form_cash.html. Otherwise - another page.

A small update to my function to make it shorter:
[tt]
function changeAction(f)
{
if (f.payment[0].checked)
f.action = &quot;form_cash.html&quot;;
else
f.action = &quot;form_cheque.html&quot;;

f.submit;
}
[/tt]
 
Thanks to all of you , it's very helpful!

STARWAY,

but I have some question....
how about if my button is a flashbutton .....
how can I link it to the code that you gave me above.

instead of the <input type submit> , i want to use the flash button with the design/image , can I use it , having the ( <script> -if ) that you gave me ?

please help me... thank you

Jhoann


 
It will not work that way.
All actions that flash performs are programmed internally using it's ActionScript.
You cannot use flash movie as simple as image or other page element.
 
i see, Now I understand ... thank you so much starway... you're so GREAT!


Jhoann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top