简体   繁体   中英

Adding href to the button either through the <script> block on inline does not redirect to another page. How to do this?

I want the "SignUp" button to redirect to another page when clicked. I tried adding href for this code through the block and inline but neither worked. Why?

<head>
    <script>
    function terms_changed(termsCheckBox){
        //If the checkbox has been checked
        if(termsCheckBox.checked){
            //Set the disabled property to FALSE and enable the button.
            document.getElementById("submit_button").disabled = false;
            document.getElementById("submit_button").style.opacity = 1;

        } else{
            //Otherwise, disable the submit button.
            document.getElementById("submit_button").disabled = true;
            document.getElementById("submit_button").style.opacity = 0.3;

        }
    }
    </script>
    </head>
    <form method="post">
    <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike" onclick="terms_changed(this)">
    <label for="vehicle1"> I have a bike</label><br>

    <input type="checkbox" id="vehicle2" name="vehicle2" value="Car" onclick="terms_changed(this)">
    <label for="vehicle2"> I have a car</label><br>

    <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat" onclick="terms_changed(this)">
    <label for="vehicle3"> I have a boat</label><br>
        <div>
         <button type="submit" id="submit_button" style="background-color:#32CD32;color:white" disabled="">Sign Up</button>
        </div>
    </form>

That button is the action submit of the form. You have to add an action to the form opening tag, ex: action="/test/" .

Then the form will redirect (means submit) together with your form data to /test/ . Change /test/ with the destination that you want.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM