Search code examples
javascripthtmlcssradio-button

How to make a radio button with a submit button that redirects to another Local Html File


Continue That is my code, and I want to redirect this to the value of each one. Can someone tell me how to do it and provide me with the javascript code. Thanks

I tried everything I found and none of them worked

<input type="radio" onclick="Form()" name="userType" value="signup-customer.html" >Client</br><input type="radio" onclick="Form()" name="userType" value="signup-provider.html" >Provider</br
<input type="radio" onclick="Form()" name="userType" value="signup-supervisor.html" >Supervisor</br>

<script>
$(function(){
    $("form").submit(function(e) {
        e.preventDefault();
        window.location = $(this).find('input[type="radio"]:checked').val();
    });
});
</script>

Solution

  • I don't know jQuery but I wrote it in plain js for you:

    <input type="radio"  name="userType"  value="signup-customer.html" >Client</br>
    <input type="radio" name="userType"  value="signup-provider.html" >Provider
    </br>
    <input type="radio"  name="userType" value="signup-supervisor.html" >Supervisor</br>
    <script>
      const inputs = document.querySelectorAll('input')
      inputs.forEach(input =>{
         input.onchange = (e) => window.location.href = e.target.value
      })
    </script>