OM The Eternity OM The Eternity - 6 months ago 35
HTML Question

How to redirect to a particular link if checkbox is checked using javascript?

How to redirect to a particular link if checkbox is checked using javascript?

I am doing this but its not working for me..

<input type="checkbox" name="yousendit" id="yousendit" value="1" onselect="return yousendit();"/>

<script type=javascript>
function yousendit()
{
if(document.getElementById('yousendit').checked== "checked")
{
window.location='https://www.yousendit.com/dropbox?dropbox=mydomain';
return false;
}
return true;

}
</script>


Please help

Answer

There are some problems with your source. Here is the working version:

<input type="checkbox" name="yousendit" id="yousendit" value="1" onclick="return yousendit();"/>
<script>
function yousendit(){
    if(document.getElementById('yousendit').checked){
        window.location='https://www.yousendit.com/dropbox?dropbox=mydomain';
        return false;
    }
    return true;

}
</script>

Changes:

  • onclick instead of onselect
  • checkboxes' checked property is boolean