SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to add another level

    hi, i have a 2 level related select form and like to add another level, but dont know how, anyone has some idea plz! thanks.

    here's the 2level form
    HTML Code:
    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    <!--
     function hide(id){
    if (document.getElementById && document.createTextNode){
    spans=document.getElementById('mainform').getElementsByTagName('span');
    m=document.getElementById('mainform');
    for (i=0;i<spans.length;i++){
    	m.getElementsByTagName('span')[i].style.visibility='hidden';					
    	m.getElementsByTagName('p')[i].style.background='#eee';					
    	m.getElementsByTagName('p')[i].style.borderColor='#ccc';					
    }
    if(id!='none'){			
    	m.getElementsByTagName('span')[id].style.visibility='visible';					
    	m.getElementsByTagName('p')[id].style.background='#ffc';					
    	m.getElementsByTagName('p')[id].style.borderColor='#000';					
    		}
    	}
    }
    
    function popsel(choice){
    	var opts=new Array();
    	opts[1]=" ,a1,a2".split(',');
    	opts[2]=" ,b1,b2,b3".split(',');
    	document.forms[0].select1.options.length=0;
    	topop=opts[choice];
    	document.forms[0].select1.options.length=topop.length;
    	for (i=0;i<topop.length;i++){
    	document.forms.example.select1.options[i].text=topop[i];
    	}
    }	
    //-->
    </script>	
    </head>
    <body onload="hide('none')">
    <form name="example">
    <label for="choice">Category</label>
    <select name="choice" id="choice" onchange="popsel(this.options[this.selectedIndex].value)">
    	<option value="0"></option>
    	<option value="1">A</option>
    	<option value="2">B</option>
    </select><BR>
    		<label for="select1">Sub-Cat</label>
    		<select name="select1"  id="select1">
    		<option value="0"></option>
    		</select> 	<BR>
    </form>
    </body>
    </html>

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This demo is one way of doing it. A better way (more accessible) is illustrated by xSelect, but it doesn't support the extra sub-select.

    cross-forum ref
    Last edited by MikeFoster; Sep 6, 2006 at 11:09.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •