Search code examples
javascripthtmlcssradio-button

Changing the website URL with radio buttons


It's an easy question but I'm having problems with it. I want to change the website url if a radio button is checked. Here are my bootstrap radio buttons.

<div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-dark active">
        <input type="radio" name="ai" id="option1" autocomplete="off" checked> Account Information
    </label>
    <label class="btn btn-dark">
        <input type="radio" name="ps" id="option2" autocomplete="off"> Password And Security
    </label>
    <label class="btn btn-dark">
        <input type="radio" name="c" id="option3" autocomplete="off"> Contact
    </label>
</div>


Solution

  • Maybe like this

    <script>
    function change_loc(url){
      document.location.href = url;
    }
    </script>
    
    <div class="btn-group btn-group-toggle" data-toggle="buttons">
        <label class="btn btn-dark active">
            <input type="radio" name="ai" id="option1" autocomplete="off" checked> Account Information
        </label>
        <label class="btn btn-dark">
            <input type="radio" name="ps" id="option2" autocomplete="off" onclick="change_loc('https://www.google.com/')"> Password And Security
        </label>
        <label class="btn btn-dark">
            <input type="radio" name="c" id="option3" autocomplete="off" onclick="change_loc('https://www.amazon.com/')"> Contact
        </label>
    </div>