[Javascript] i need one help pls

Laurent Muchacho elmuchacho at gmail.com
Tue Sep 27 05:28:07 CDT 2005


Hi Yoga,

Small correction on the previous solution I sent you don't need the ID on 
the root ul
The solution below will go through all the checkbox and assign the event 
onclick to them you need the id on the root ul for this to work.

Regards

Laurent

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title></title>
</head>
<body>
<form name="frm">
<ul id="checkBoxList">
 <li><input type="checkbox">Northfrica
  <ul>
   <li><input type="checkbox" >Algeria</li>
   <li><input type="checkbox" >Egypt</li>
   <li><input type="checkbox" >Libyan Arab</li>
   <li><input type="checkbox">Mauritania</li>
  </ul>
 </li>

 <li><input type="checkbox">Sub-Sahara Africa
  <ul>
   <li><input type="checkbox" >Angola</li>
   <li><input type="checkbox" >Benin</li>
   <li><input type="checkbox" >Botswana</li>
   <li><input type="checkbox" >Burkina Faso</li>
   <li><input type="checkbox" >Burundi</li>
  </ul>
 </li>
 <li><input type="checkbox">Near East
  <ul>
   <li><input type="checkbox" >Afghanistan</li>
   <li><input type="checkbox" >Bahrain</li>
   <li><input type="checkbox">Cyprus</li>
   <li><input type="checkbox">Djibouti</li>
   <li><input type="checkbox" >Iran</li>
   <li><input type="checkbox">Iraq</li>
  </ul>
 </li>
</ul>
</form>
<script type="text/javascript">
function SelectCountry(){
 var checkBox_list = this.parentNode.getElementsByTagName('INPUT');
 for(var i=0;i<checkBox_list.length;i++){
  checkBox_list[i].checked =  this.checked
 }
}
function assignOnClick(){
 var allCheckBox = 
document.getElementById('checkBoxList').getElementsByTagName('INPUT')
 for(var i=0;i<allCheckBox.length;i++){
  allCheckBox[i].onclick = SelectCountry;
 }

}
window.onload = assignOnClick;
</script>
</body>
</html>

----- Original Message ----- 
From: "yoga rajan" <yogaraja_g at yahoo.com>
To: <Javascript at LaTech.edu>
Sent: Tuesday, September 27, 2005 8:05 AM
Subject: [Javascript] i need one help pls


> Hello friend
> i need one help
>
> this is my sample program
>
>
>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual
> Studio 6.0">
> <TITLE></TITLE>
> </HEAD>
> <BODY>
> <form name="frm">
> <ul>
> <li><input type="checkbox"
> name=checkbox1>Northfrica</li>
>  <ul >
>    <li><input type="checkbox" >Algeria</li>
>    <li><input type="checkbox" >Egypt</li>
>    <li><input type="checkbox" >Libyan Arab</li>
>    <li><input type="checkbox">Mauritania</li>
> </ul>
>
> <li><input type="checkbox">Sub-Sahara Africa</li>
>  <ul>
>    <li><input type="checkbox" >Angola</li>
>    <li><input type="checkbox" >Benin</li>
>    <li><input type="checkbox" >Botswana</li>
>    <li><input type="checkbox" >Burkina Faso</li>
>    <li><input type="checkbox" >Burundi</li>
> </ul>
>
> <li><input type="checkbox">Near East</li>
> <ul>
>    <li><input type="checkbox" >Afghanistan</li>
>    <li><input type="checkbox" >Bahrain</li>
>    <li><input type="checkbox">Cyprus</li>
>    <li><input type="checkbox">Djibouti</li>
>    <li><input type="checkbox" >Iran</li>
>    <li><input type="checkbox">Iraq</li>
> </ul>
> </ul>
> </form>
> </BODY>
> </HTML>
>
> main list is continent
> and sub list is country
>
>
> my question:
>
> 1. if i select any continent inner countries should be
> checked
> if i uncheck the continent ,inner countries should be
> unchecked
>
> now i am not giving checkbox name
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript 




More information about the Javascript mailing list