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='';
return false;
}
return true;
}
</script>
Please help
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./dropbox?dropbox=mydomain';
return false;
}
return true;
}
</script>
Please help
Share Improve this question edited May 28, 2012 at 7:42 halkazzar 751 silver badge7 bronze badges asked Sep 11, 2010 at 9:10 OM The EternityOM The Eternity 16.2k44 gold badges125 silver badges187 bronze badges4 Answers
Reset to default 6There 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./dropbox?dropbox=mydomain';
return false;
}
return true;
}
</script>
Changes:
onclick
instead ofonselect
- checkboxes'
checked
property is boolean
I don't believe onselect
is a valid event for a checkbox, but I may be wrong on that.
Regardless, this works.
document.getElementById('yousendit').onclick = function() {
if (this.checked==true)
alert('checked'); // Or in your case, window.location = 'whatever.html';
}
Fiddle http://jsfiddle/Tm6q6/
use this code
<input type="checkbox" value="xyz.php"
name="checket"
onClick="if (this.checked) { window.location = this.value; }">
instead of using onselect use onclick event.
and instead of writing
if(document.getElementById('yousendit').checked== "checked")
write if(document.getElementById('yousendit').checked)