Created
June 24, 2013 14:31
-
-
Save vgoklani/5850464 to your computer and use it in GitHub Desktop.
Javascript checkbox notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/10436764/how-to-set-default-checkbox-status-with-javascript | |
// javascript to check if checkbox is checked / unchecked | |
// To change checkbox state try this: | |
document.getElementById("RememberMe").checked = true; | |
// If you need to change the value of checkbox as an input element use: | |
document.getElementById("RememberMe").value = "New Value"; | |
// However, you can set default value and state in HTML markup: | |
<input id="RememberMe" name="RememberMe" type="checkbox" value="The Value" checked="checked" /> | |
// jquery code | |
$('#RememberMe').attr('checked', true); | |
///////////// | |
// http://bl.ocks.org/nsonnad/4175202 | |
<div> | |
<input type="checkbox" id="bric" onclick="briclight()">BRICs</input> | |
<input type="checkbox" id="mist" onclick="mistlight()">MIST</input> | |
</div> | |
// ugly javascript for highlighting the two groups of countries | |
function briclight() { | |
var chkbox = document.getElementById("bric"); | |
if (chkbox.checked) { | |
document.getElementById("China").style.cssText = "opacity:1;", | |
document.getElementById("Brazil").style.cssText = "opacity:1;", | |
document.getElementById("India").style.cssText = "opacity:1;", | |
document.getElementById("Russia").style.cssText = "opacity:1;" | |
} else { | |
document.getElementById("China").style.cssText = "", | |
document.getElementById("Brazil").style.cssText = "", | |
document.getElementById("India").style.cssText = "", | |
document.getElementById("Russia").style.cssText = ""; | |
}}; | |
function mistlight() { | |
var chkbox = document.getElementById("mist") | |
if (chkbox.checked) { | |
document.getElementById("Mexico").style.cssText = "opacity:1;", | |
document.getElementById("Indonesia").style.cssText = "opacity:1;", | |
document.getElementById("S Korea").style.cssText = "opacity:1;", | |
document.getElementById("Turkey").style.cssText = "opacity:1;" | |
} else { | |
document.getElementById("Mexico").style.cssText = "", | |
document.getElementById("Indonesia").style.cssText = "", | |
document.getElementById("S Korea").style.cssText = "", | |
document.getElementById("Turkey").style.cssText = ""; | |
}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment