Home   Free Applications   Code Snippets   Fun Stuff 
 
 You are here: Home > Code Snippets > JavaScript
Register   Login  

 
Site Navigation


Print Print this page
Email E-mail this page
Bookmark Add to Favorites

 
Drop Down Changer

Posted by on Friday, October 17, 2003 (EST)

changes the content of a dropdown

JavaScript:

<SCRIPT LANGUAGE="JavaScript1.1" TYPE="text/javascript">
  <!--
  var aryDropdownList = new Array();
  var intArrayCount = 0;
 
  function defineDropdown(strName, strList)
  {
    var objDropdownList = new Object();
    objDropdownList.Name = strName;
    objDropdownList.List = new Array();
    var aryTempList = strList.split("|");
    for (var i = 0; i < aryTempList.length; i++) {
      var aryTempValue = aryTempList[i].split(":");
      objTempValues = new Object();
      objTempValues.Display = aryTempValue[0];
      objTempValues.Value = aryTempValue[1];
      objDropdownList.List[i] = objTempValues
    }
    aryDropdownList[intArrayCount] = objDropdownList;
    intArrayCount++;
  }
 
  function changeDropdown(objTargetElement, strName)
  {
    for (var i = 0; i < aryDropdownList.length; i++) {
      if (aryDropdownList[i].Name == strName) {
        objTargetElement.length = aryDropdownList[i].List.length;
        var intOption = 0
        for (var x = 0; x < aryDropdownList[i].List.length; x++) {
          objTargetElement.options[intOption].text = aryDropdownList[i].List[x].Display;
          objTargetElement.options[intOption].value = aryDropdownList[i].List[x].Value;
          intOption++
        }
        return true;
      }
    }
    return false;
  }
 
  defineDropdown("ALL", "Project Test:1|Project 2:2|Project 3:3|Project 4:4");
  defineDropdown("QA", "Project 2:2");
  defineDropdown("DEV", "Project 3:3|Project 4:4");
  defineDropdown("PROD", "Project Test:1");
 
  //-->
</SCRIPT>

HTML:

<form action="">
<select name="Filter" size="1" onChange="changeDropdown(this.form.Projects, this.options[this.selectedIndex].value)">
 <option value="ALL">All Projects</option>
 <option value="DEV">Projects in Development</option>
  <option value="QA">Projects in QA</option>
  <option value="PROD">Projects in Production</option>
</select>
<select name="Projects" size="1">
 <option value="">____________________________________</option>
  <option value=""></option>
  <option value=""></option>
  <option value=""></option>
  <option value=""></option>
</select>
</form>

Comments:

regd split
By ? on Tuesday, February 28, 2006 (EST)
it gives error in some browsers saying it doesnt support

Reply to this Comment

helloooooooooooooooooo
By ? on Sunday, March 12, 2006 (EST)
fdsfgsdgdsfggggggggggggg

Reply to this Comment

Add Your Comment



Top
 
CNET News.com


Tech news and business reports by CNET News.com. Focused on information technology, core topics include computers, hardware, software, networking, and Internet media.

  • Hands-on with the new Joost: Software still required
    The new Joost is no longer a piece of software, but you'll still need a special site-specific plug-in to run it.

  • Microsoft adding to its Labs collection
    Startup Labs will be an effort under Ray Ozzie, joining others including Live Labs, adCenter Labs, and Office Labs.

  • Security Bites 113: The security of Chrome
    Billy Hoffman of HP Web Security talks about Google's new browser, how it handles Javascript and what it means for Web 2.0 security.

  • Are Demo and TechCrunch50 fragmenting their audiences?
    With both events scheduled to start Monday, many press, as well as venture capitalists and others are having to choose which one to attend.

  • A user guide to following DemoFall and TechCrunch50
    More than 100 products are going to be introduced during the week of September 8. Will they be any good?


    Copyright 1995-2008 CNET Networks, Inc. All rights reserved. Last Refreshed 9/5/2008 3:45:14 PM
  •