try this code and what use for launch button . if you said try my self.... <script language="JavaScript"> function checkAll(field) { for (i = 0; i < field.length; i++) field.checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field.checked = false ; } </script> <form onsubmit="bornday" name="myform"> <div><input type="checkbox" id="facebook" name="myCheckbox" /> facebook</div> <div><input type="checkbox" id="google" name="myCheckbox"/> Google</div> <div><input type="checkbox" id="yahoo" name="myCheckbox"/> Yahoo</div> <input type="button" value="uncheck!" onclick="uncheckAll(document.myform.myCheckbox)" /> <input type="button" value="launch!" onclick="checkAll(document.myform.myCheckbox)" /> </form>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="js/1.4.3jquery.js"></script><script type="text/javascript">$(document).ready(function(){ var domains = ["http://www.facebook.com","http://www.google.com","http://www.Yahoo.com"]; $("#ckAll").click(function(){ $('[name="myCheckbox"]').each(function(){ $(this).attr("checked","checked"); Â Â }) return false; }) $("#unckAll").click(function(){ $('[name="myCheckbox"]').each(function(){ $(this).attr("checked",""); Â Â }) return false; }) $("#lunch").click(function(){ $('[name="myCheckbox"]:checked').each(function(){ window.open(domains[$(this).attr("value")]); Â Â }) return false; })})</script><title>Test JS</title></head> <body><form name="myform" action=""><div><input type="checkbox" name="myCheckbox" value="0" />Facebook</div><div><input type="checkbox" name="myCheckbox" value="1"/>Google</div><div><input type="checkbox" name="myCheckbox" value="2"/>Yahoo!</div><button id="lunch">Launch!</button><button id="unckAll">UnCheck</button><button id="ckAll">Check All</button> </form></body></html> PHP: I used jquery for this.. simpler
Thank you for sharing astrazone. I appreciate it. However, jquery is quite more advanced and i can't follow. just need the typical js code to do it.
If you would like to really get into this seriously you should probably learn jquery its very simple... Let me break id down for you... $("#ckAll").click(function(){ PHP: It looks for the ckAll id and goes through the function when its pressed... $('[name="myCheckbox"]').each(function(){ $(this).attr("checked","checked");   }) PHP: Here it finds every input with the name "myCheckbox" and runs each of the inputs it finds through the function changing the $(this) each time.. Then it just adds the attribute checked with the value checked... I hope that you will understand it from here. if not feel free to PM me. Good luck, astrazone
hello... i have the check/uncheck buttons working now. my problem now is the code for the launch button.
i got the solution please try this one....... <script language="JavaScript"> function checkAll(field) { for (i = 0; i < field.length; i++) field.checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field.checked = false ; } function siteOpener() { var checkboxArr=document.myform.myCheckbox; for(var i=0;i<checkboxArr.length;i++) { if(checkboxArr.checked) { window.open (checkboxArr.value,"mywindow"+i); } } } </script> <form onsubmit="bornday" name="myform"> <div><input type="checkbox" id="facebook" name="myCheckbox" value="http://www.facebook.com/" /> facebook</div> <div><input type="checkbox" id="google" name="myCheckbox" value="http://google.com" id="CheckboxGroup1_0" /> Google</div> <div><input type="checkbox" id="yahoo" name="myCheckbox" value="http://yahoo.com" id="CheckboxGroup1_1" /> Yahoo</div> <input name="openSites" type="button" value="Launch" onclick="siteOpener();"/> <input type="button" value="Uncheck!" onclick="uncheckAll(document.myform.myCheckbox)" /> <input type="button" value="Check All" onclick="checkAll(document.myform.myCheckbox)" /> </form>