Results 1 to 3 of 3

Thread: Radio Button with 2 Different Actions

  1. #1
    Join Date
    Jun 2012

    Radio Button with 2 Different Actions

    Hi all,

    I have a very simple form that has 2 radio buttons. 1 for EFT and 1 for Credit Cards.

    When radio button 1 is selected and someone presses submit I want it to redirect to one of my pages which is easy. But when radio 2 is selected i want it to trigger this: href="javascript:;" class="simpleCart_checkout" which will use script running on my page to send cart data and other variables to PayFast (a third party payment solution).

    This is what I have so far:

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function usePage(frm,nm){
    for (var i_tem = 0, bobs=frm.elements; i_tem < bobs.length; i_tem++)
    <form action="#" method="post" onsubmit="usePage(this, 'bob');">
    <input type="radio" name="bob" value="http://www.sunshineinabottle.co.za/banking-details/">EFT<br>
    <input type="radio" name="bob" value="">Credit/Debit<br>
    <input type="submit" value="Go">

    I'm very new to html and all but when I changed the 2nd radio button to look as follows, it worked, but it redirected when the radio button is pressed rather than the submit button pressed:

    <input type="radio" name="bob" href="javascript:;" class="simpleCart_checkout">Credit/Debit<br>

    Any help would be great

  2. #2
    Join Date
    Mar 2011
    The code:
    <input type="radio" name="bob" href="javascript:;" class="simpleCart_checkout">Credit/Debit<br>
    won't do anything because the 'href' attribute doesn't mean anything and is set to simply 'javascript:'. You can't always copy and paste code from one form to another and expect it to work. You either need to learn more about HTML and JavaScript or get someone to help you work on your site directly. The issues involved are probably too detailed to solve in an online forum. Good luck!
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jan 2007
    If I understand correctly, you're halfway there already:

    PHP Code:
    function usePage(frm,nm){
      for (var 
    i_tem 0bobs=frm.elementsi_tem bobs.lengthi_tem++)

    You're Credit/Debit field needs to be updated with the appropriate URL to submit to:

    HTML Code:
    <input type="radio" name="bob" value="http://otherprocessor.com/service.whatever">Credit/Debit<br>
    And, if you need to format the cart items differently, for the other processor, you can do in usePage() as well:

    PHP Code:
    function usePage(frm,nm){
      for (var 
    i_tem 0bobs=frm.elementsi_tem bobs.lengthi_tem++)

      if (
    frm.action == 'http://otherprocessor.com/service.whatever') {
    // do whatever reformatting of form fields you need to do here.
        // you could even build a hidden form, submit THAT, and return false here,
        // to prevent the original form from submitting.

    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center