www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 03-12-2007, 07:21 PM
    livebymyheart livebymyheart is offline
    Registered User
     
    Join Date: Mar 2007
    Posts: 14
    Modifying a drop down menu dynamically

    Hello:

    I'd very much appreciate if someone would guide me how to implement the following function (an approach would be great, if not the outright code), which is no doubt a common feature of many websites but too much out of my depth at the present time. (if javascript is the wrong venue, being directed to a better solution would be equally helpful.)

    I am selling products in which designs are printed. two drop-down forms allow input of product(t-shirt, sweatshirt, bib and mouse pads, etc) and size (S, M L, XL). How do I make the choices of size dependent on what is entered as a product, so that for example, a T-shirt would allow entry of S,M,L while a mouse pad would have no choices.

    Currently, it is coded essentially as follows:

    <form action="addtoorder.php" method=<post>

    <label><br />
    Please Enter the Product

    <SELECT NAME="prodcode" SIZE="1">
    <OPTION SELECTED>-
    <OPTION>Adult's Lightweight Tee
    <OPTION>Adult's Heavyweight Tee
    <OPTION>Mousepad
    <OPTION>Baby Bib - Blue Lining
    <OPTION>Baby Bib - Pink Lining
    </SELECT>


    </br>
    Please Enter the Size
    <SELECT NAME="size" SIZE="1">
    <OPTION SELECTED>-
    <OPTION>S
    <OPTION>X
    <OPTION>L
    <OPTION>XL
    <OPTION>XXL
    </SELECT>
    </br>

    <label><br />
    <input type="submit" value="ADD TO SHOPPING CART" />
    </form>


    Thanks In Advance

    Steve
    Reply With Quote
      #2  
    Old 03-13-2007, 06:31 AM
    Sorehead Sorehead is offline
    Red or Blue?
     
    Join Date: Feb 2007
    Location: Scotland
    Posts: 122
    Hi,

    This is a snippet from a similar task I had for a client.
    The page is in asp itself, which pulls the subcategories from a database, just so you understand why there isnt an array for each category, but you could apply the same method to your process.

    Basically each subcategory is stored in an array which is relevantly named to the first category elements.

    In the function subcatadd() the first for loop determines which drop down item is selected from the first category, then the switch statement takes that info and removes any subcategories already there and loads the relevant subcategories.

    Hope that gives you a guideline to work by.


    HTML 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>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript" language="javascript">
    <!--
    
    	var cat5 = new Array();
    	
    		cat5[0] = "Bulgaria";
    		
    		cat5[1] = "Dubai";
    		
    		cat5[2] = "America";
    		
    		cat5[3] = "Canada";
    		
    		cat5[4] = "Spain";
    		
    		cat5[5] = "France";
    		
    		cat5[6] = "Jamaica";
    		
    	var cat9 = new Array();
    	
    		cat9[0] = "Travel";
    		
    		cat9[1] = "Home";
    		
    		cat9[2] = "Car";
    		
    	
    	function subcatadd()
    		{
    		var i, num, x, y
    		
    		for ( i = 0; i < document.addlink.category.length; i++ )
    			{
    			if ( document.addlink.category.options[i].selected == true )
    				{
    				num = i;
    				}
    			}
    			
    		switch (num)
    			{
    			
    			case 1:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat1 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat1[x],cat1[x]);
    				}
    			  break
    			
    			case 2:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat2 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat2[x],cat2[x]);
    				}
    			  break
    			
    			case 3:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat3 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat3[x],cat3[x]);
    				}
    			  break
    			
    			case 4:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat4 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat4[x],cat4[x]);
    				}
    			  break
    			
    			case 5:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat5 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat5[x],cat5[x]);
    				}
    			  break
    			
    			case 6:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat6 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat6[x],cat6[x]);
    				}
    			  break
    			
    			case 7:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat7 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat7[x],cat7[x]);
    				}
    			  break
    			
    			case 8:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat8 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat8[x],cat8[x]);
    				}
    			  break
    			
    			case 9:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat9 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat9[x],cat9[x]);
    				}
    			  break
    			
    			case 10:
    				
    			  while ( document.addlink.subcat.length > 0 )
    			  	{
    				document.addlink.subcat.remove(0);
    				}						
    				
    			  for ( x in cat10 )
    				{
    				document.addlink.subcat.options[x] = new Option(cat10[x],cat10[x]);
    				}
    			  break
    			
    			}
    		
    		}
    		
    		
    function vselect(frm)
    	{
    	if ( document.addlink.category.selectedIndex == 0 )
    		{
    		alert("Please Select a Category");
    		}
    	else
    		{
    		document.addlink.submit();
    		}
    	}
    
    
    -->
    </script>
    
    </head>
    
    <body>
    <form name="addlink" action="addlink.asp" method="post" enctype="multipart/form-data">
    <p><select name="category" onChange="subcatadd();">
    						<option value="no_select">Please Select</option>
    						
    											<option value="Property News">Property News</option>
    
    						
    											<option value="Mortgage advisors">Mortgage advisors</option>
    						
    											<option value="Financial Help">Financial Help</option>
    						
    											<option value="Free Debt advice">Free Debt advice</option>
    						
    											<option value="Property Abroad">Property Abroad</option>
    						
    											<option value="Utility Services">Utility Services</option>
    						
    											<option value="DIY">DIY</option>
    
    						
    											<option value="Interior Design">Interior Design</option>
    						
    											<option value="Insurance">Insurance</option>
    						
    						</select></p><br />
    <p><select name="subcat" id="subcategory">
    							<option value="no_select">Please Select</option>
    
    						</select></p>
    						</form>
    
    </body>
    </html>
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:13 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.