www.webdeveloper.com
Results 1 to 5 of 5

Thread: how to loop the chain select box..

  1. #1
    Join Date
    Aug 2010
    Posts
    11

    how to loop the chain select box..

    how to loop the form, so that there would be a multiple select boxes..
    here is the problem if i loop the form only..

    http://i5.photobucket.com/albums/y17...am/example.png

    the code..
    Code:
    <form action="" method="post" name="form1">
    <select name="college" id="college" onChange="selected(this.selectedIndex)">
      <option value="0" selected>Select college..</option>
      <option value="1">Engineering</option>
      <option value="2">Business Administration</option>
      <option value="3">Arts and Science</option>
      <option value="4">Fine Arts</option>
    </select>              
    <select name="course" id="course">
      <option value="0" selected>Select course..</option>
    </select>  
    </form>
     
    <script type="text/javascript">
    
        var colleges=document.form1.college
        var courses1=document.form1.course
        
        var course=new Array()
    		
        course[0]=['Select course..']    
        course[1]=['CE','COE','EE','ECE','IE','ME','CS','IS','IT']    
        course[2]=['BSA-CAS','BSA','BSBA-FM','BSBA-BEC','BSBA-MGE','BSBA-MKM','BSBA-MA','BSENT']    
        course[3]=['AB-Comm Arts','Tourism','HRM', 'Sec. Mgt.']
    	course[4]=['BFA','BFA-Int Design','BFA-Painting','BID']
        
        function selected(collgrp){                
            courses1.options.length=0                    
            if(collgrp >= 0){
    			
                for(i=0; i<course[collgrp].length; i++){
                courses1.options[courses1.options.length]=new Option(course[collgrp][i])
            }
        }
        }
    	
    </script>

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    you want this?

    Code:
    <!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>
    <title>how to loop the chain select box</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
    <!--
    div#main{
    text-align:center;
    padding-top:100px;
    }
    -->
    </style>
    <script type="text/javascript">
    <!--
    var corz = [
    ['Select course..'],
    ['CE','COE','EE','ECE','IE','ME','CS','IS','IT'],
    ['BSA-CAS','BSA','BSBA-FM','BSBA-BEC','BSBA-MGE','BSBA-MKM','BSBA-MA','BSENT'],
    ['AB-Comm Arts','Tourism','HRM', 'Sec. Mgt.'],
    ['BFA','BFA-Int Design','BFA-Painting','BID']
    ];
    
    function sel(collgrp){                
    var course = document.getElementById('course');
    course.options.length = 0;
    if(collgrp >= 0){
    for(var i = 0; i < corz[collgrp].length; i++){
    course.options[course.options.length] = new Option(corz[collgrp][i]);
    }
    }
    }
    //-->
    </script>
    </head>
    <body>
    <div id="main">
    <form action="" method="post" name="form1">
    <select name="college" id="college" onchange="sel(this.selectedIndex);this.blur();">
    <option value="0" selected="selected">Select college..</option>
    <option value="1">Engineering</option>
    <option value="2">Business Administration</option>
    <option value="3">Arts and Science</option>
    <option value="4">Fine Arts</option>
    </select>              
    <select name="course" id="course"><option value="0" selected="selected">Select course..</option></select>  
    </form>
    </div>
    </body>
    </html>
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Aug 2010
    Posts
    11
    i want to have an output like this sir...

    http://i5.photobucket.com/albums/y17...alam/loops.jpg

    thanks for the help..

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,390

    Question

    Quote Originally Posted by pchsmvp View Post
    i want to have an output like this sir...

    http://i5.photobucket.com/albums/y17...alam/loops.jpg

    thanks for the help..
    What's wrong with 'Podanak's solution?

    If you really want it to look like your '.jpg', you will need to define
    more of the selections than you have provided.

    For example, how many selections under "Arts and Science" and what are the selections to display for each of those options?

    Perhaps 'Podanak' is better at mind reading than I am

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    pchsmvp i can't understand clearly what is really needed to be done my english is not that good..
    anyway you can take this example and modify it the way you need. if not may be it would be better to make your page less interactive
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles