Search code examples
javascripthtmlonclick

Onclick on href in html


I want to make a button that will redirect me to another page.

the code:

 <div align="right" ><input type="submit" id="logout" onclick="location.href=/login?dis=yes" value="Sign Out" ></div><BR>

but when i press the button, i dont get any redirection to the other page.

any idea why?


Solution

  • Your current code, even if the syntax is fixed by adding quotation marks, creates a button that does not work when JavaScript is disabled. The simpler and safer approach is a small HTML form:

    <form action="/login">
    <input type=hidden name=dis value=yes>
    <input type=submit value="Sign Out">
    </form>
    

    To achieve the desired styling, you could add the following stylesheet:

    form { display: inline; float: right; }