[Javascript] i need one help pls

Laurent Muchacho elmuchacho at gmail.com
Tue Sep 27 05:11:16 CDT 2005


Hi Yoga,

Found below the solution of what you where looking for.
I think the way you had your ul formatted was displaying correctly but it 
was not correct found below the way I did it by nesting the ul (child) into 
the li(parent)
I applied an id to the ul (root) to make it easier to access in the DOM
I put an onclick function on each checkbox who contain a list of country (I 
could have made a recursive function who was making this work with any 
checkbox and child of this one if you need this functionnality let me know)

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" onclick="selectCountry(this)">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" onclick="selectCountry(this)">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" onclick="selectCountry(this)">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(o){
 var checkBox_list = o.parentNode.getElementsByTagName('INPUT');
 for(var i=0;i<checkBox_list.length;i++){
  checkBox_list[i].checked =  o.checked
 }
}
</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