Required checkbox with javascript to click on link

1

Good evening everyone!

I'm making a website for a college job, and what I want to do is this: I have a simple HTML menu whose options are "Profile View", "Edit Profile" and "Remove Profile". In the latter, there is a checkbox saying that the user is sure of what he wants. To remove the profile the person must first have selected it (similar to those "I have read and I accept the terms"). If you click on "remove profile" without first selecting the checkbox, you should see an error message.

My question: How to build a code that requires the user to click on the checkbox before to remove the profile and be directed to another page, and if it does not display an error message?

See the code:

       <ul id="menuperfil">
           <li><a href="perfilview.html">Visualizar Perfil</a></li>     
           <li><a href="perfiledit.html">Editar Perfil</a></li>
           <li><a href="perfildelete.html">Remover Perfil</a>
             <form>
        <input type="checkbox" name="remover">Tenho certeza de que desejo remover o perfil.
             </form></li>
       </ul>

With CSS it looks like this:

Hey, guys! Any suggestions ??

Thank you for your attention!

    
asked by anonymous 31.10.2015 / 03:45

1 answer

1
<a href="#" onclick="fcnConfirma();">Remover Perfil</a>
<input type="checkbox" id="remover" name="remover">Tenho certeza de que desejo remover o perfil.


<script type="text/javascript">
    function fcnConfirma() {
        if (!document.getElementById('remover').checked) {
            alert("Marque a opção:\nTenho certeza de que desejo remover o perfil.");
            return;
        }else{
            window.open("perfildelete.html","_self")
            // window.open("perfildelete.html","_blank")
        }
    }
</script>
    
31.10.2015 / 12:59