Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Categories & subcategories & more subcategories!?

    Hi i don't know anything about JavaSctipt, but i need one little script for form. I need something like that script in attachment only whit 3 "select meny".

    For example in first i choose country, then i get in second the list of states in the country, and when i choose state in third i get list of cities whit in the state.

    Can anyone write this for me?

    Please help me.

    Thank You!
    Attached Files Attached Files
    • File Type: txt 41.txt (854 Bytes, 114 views)

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    only works in NS... sorry could fix it
    Attached Files Attached Files

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this migth help get an idea of how to do it.
    Code:
     
    <head>
      <script language="JavaScript1.2">
    	  var i=0;
    		var tc=new Array();
    		
    		tc[i++]=new Array('USA',new Array('SC','Washington','New York'),new Array('NC','Baltimore','Orleans'));
    		tc[i++]=new Array('Europe',new Array('Germany','Berlin'));
    		function fillCategory()
    	  {
    		  for (loop =document.getElementById('Category').options.length-1; loop > -1; loop--)
          {
           document.getElementById('Category').options[loop] = null;
          }
    
          for (loop = 1; loop < tc[document.getElementById('Type').selectedIndex].length; loop++)
          {
            document.getElementById('Category').options[loop-1] = new Option(tc[document.getElementById('Type').selectedIndex][loop][0]);
          }
    			fillSubCategory();
        }
    
    		function fillSubCategory()
    	  {
    		  
    		  for (loop =document.getElementById('Subcategory').options.length-1; loop > -1; loop--)
          {
           document.getElementById('Subcategory').options[loop] = null;
          }
    			
    			if(tc[document.getElementById('Type').selectedIndex][document.getElementById('Category').selectedIndex+1].length>1)
    			{
          for (loop = 1; loop < tc[document.getElementById('Type').selectedIndex][document.getElementById('Category').selectedIndex+1].length; loop++)
          {
            document.getElementById('Subcategory').options[loop-1] = new Option(tc[document.getElementById('Type').selectedIndex][document.getElementById('Category').selectedIndex+1][loop]);
          }
    			}
      	}
      </script>
    </head>
    <form name="form1" method="post" action="">
    <table border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td>Step 1</td>
        <td>
    		<select  name="Type" id="Type" onchange="fillCategory();">
          <script language="JavaScript1.2">
    	    var i=0;
    		  for(i=0;i<tc.length;i++)
    		  {
    		    document.write('<option value='+i+'>'+tc[i][0]+'</option>')
    		  }
          </script>
        </select>
        </td>
      </tr>
      <tr>
        <td>Step 2</td>
        <td>
    		<select  name="Category" id="Category" onchange="fillSubCategory();">
          <script language="JavaScript1.2">
    	    var i=0;
      		for(i=1;i<tc[0].length;i++)
    	  	{
    		    document.write('<option value='+i+'>'+tc[0][i][0]+'</option>')
       		}
          </script>
        </select>
    		</td>
      </tr>
      <tr>
        <td>Step 3</td>
        <td>
    		<select  name="Subcategory" id="Subcategory">
        <script language="JavaScript1.2">
    	  var i=0;
    		for(i=1;i<tc[0][1].length;i++)
    		{
    		  document.write('<option value='+i+'>'+tc[0][1][i]+'</option>')
    		}
        </script>
        </select>
    		</td>
      </tr>
    </table>
    </form>

  • #4
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you all!

    I think that will do the job!


  •  

    Posting Permissions

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