0

I'm trying to add the action to an HTML form based on which radio button a user has selected. What I have written works so far, except it's not redirecting to the full URL I have set. Here's my code:

$("input[name$='discount_options']").click(function () {
        if (document.membershipIndividualJoin.discount_options[0].checked == true) {
            document.membershipIndividualJoin.action = "https://netdonor.net/page/48617/membership/2?membershipTypeId=129";
            console.log("checked regular");
        }

        else if (document.membershipIndividualJoin.discount_options[1].checked == true) {
            document.membershipIndividualJoin.action = "https://netdonor.net/page/48625/membership/2?membershipTypeId=132";
        }

        else if (document.membershipIndividualJoin.discount_options[2].checked == true) {
            document.membershipIndividualJoin.action = "https://netdonor.net/page/48629/membership/2?membershipTypeId=133";
        }

        else if (document.membershipIndividualJoin.discount_options[3].checked == true) {
            document.membershipIndividualJoin.action = "https://netdonor.net/page/48622/membership/2?membershipTypeId=130";
        }

        return true;
    });

Instead of redirecting to the full URL, the page is redirecting to https://netdonor.net/page/48629/membership/2 which doesn't work for my purposes. Is there any way to get around this?

kait
  • 305
  • 2
  • 3
  • 11
  • 2
    You can't use query params on an action string. You'd have to use hidden inputs. Check this post out: https://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear – bgaynor78 Sep 24 '19 at 14:32
  • 1
    Try replace `document.membershipIndividualJoin.action = ...` to `window.location.href = ...` – Chiu Sep 24 '19 at 14:53

1 Answers1

0

You can try like this

    <p>Please select</p>
    <input type="radio" name="discount_options" value="1"> 1
    <input type="radio" name="discount_options" value="2"> 2
    <input type="radio" name="discount_options" value="3"> 3
    <input type="radio" name="discount_options" value="4"> 4

<script>
$("input[name='discount_options']").click(function () {
    if ($(this).attr("value") == 1) {
      window.location.href = "https://netdonor.net/page/48617/membership/2?membershipTypeId=129";
    }

    else if ($(this).attr("value") == 2) {
        window.location.href = "https://netdonor.net/page/48625/membership/2?membershipTypeId=132";
    }

    else if ($(this).attr("value") == 3) {
        window.location.href = "https://netdonor.net/page/48629/membership/2?membershipTypeId=133";
    }

    else if ($(this).attr("value") == 4) {
        window.location.href = "https://netdonor.net/page/48622/membership/2?membershipTypeId=130";
    }
});
</script>
Larry
  • 26
  • 1