Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Display textbox based on selection from dropdown list

  1. #11
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Display Text Box from value of drop down

    i have been reading your posting which have been helpful with what i am trying to do, but i am stuck on this:

    i have created a js that when you select the value of the 1st drop down menu it changes the options on the next drop down box depending on what is selected, what i need to do now is when they select the option in the 2nd drop down box i need it to display the text box depending on which value they select, i have an html page reading a .js for the drop down menu options, so how would i be able to do this when the options are in the .js code and not in the html?!

    here is the code for the drop down boxes as well as the html that reads it:

    JS Script
    -----------
    JS Script
    ---------
    function fillCategory(){
    // this function is used to fill the category list on load
    addOption(document.drop_list.Category, "ABMS", "ABMS", "");
    addOption(document.drop_list.Category, "AAA", "AAA", "");
    addOption(document.drop_list.Category, "BBTT", "BBTT", "");
    addOption(document.drop_list.Category, "Empowernet", "Empowernet", "");
    addOption(document.drop_list.Category, "Esource", "Esource", "");
    addOption(document.drop_list.Category, "Etrain", "Etrain", "");
    addOption(document.drop_list.Category, "MACs", "MACs", "");
    addOption(document.drop_list.Category, "Marlin", "Marlin", "");
    addOption(document.drop_list.Category, "Secure", "Secure", "");
    addOption(document.drop_list.Category, "Sheer", "Sheer", "");
    }

    function SelectSubCat(){
    // ON selection of category this function will work

    removeAllOptions(document.drop_list.SubCat);
    addOption(document.drop_list.SubCat, "", "Select Category:", "");

    if(document.drop_list.Category.value == 'ABMS'){
    addOption(document.drop_list.SubCat,"Invalid Login", "Invalid Login");

    addOption(document.drop_list.SubCat,"Partners Missing", "Partners Missing");
    }


    if(document.drop_list.Category.value == 'AAA'){
    addOption(document.drop_list.SubCat,"Invalid Password", "Invalid Password");
    }


    if(document.drop_list.Category.value == 'BBTT'){
    addOption(document.drop_list.SubCat,"Area is not available", "Area is not available");

    addOption(document.drop_list.SubCat,"Other", "Other");
    }


    if(document.drop_list.Category.value == 'Empowernet'){
    addOption(document.drop_list.SubCat,"Training not listed", "Training not listed");

    addOption(document.drop_list.SubCat,"SP not listed", "SP not listed");

    addOption(document.drop_list.SubCat,"Request Trainer Rights", "Request Trainer Rights", "");

    addOption(document.drop_list.SubCat,"LE Request", "LE Request", "");
    }


    if(document.drop_list.Category.value == 'Esource'){
    addOption(document.drop_list.SubCat,"No Permissions Found", "No Permissions Found");

    addOption(document.drop_list.SubCat,"Not Authorized", "Not Authorized");

    addOption(document.drop_list.SubCat,"Toolset change", "Toolset change", "");
    }


    if(document.drop_list.Category.value == 'Etrain'){
    addOption(document.drop_list.SubCat,"Please Try again", "Please Try again");

    addOption(document.drop_list.SubCat,"CCID", "CCID");
    addOption(document.drop_list.SubCat,"Training Not Listed", "Training Not Listed", "");

    addOption(document.drop_list.SubCat,"Page Cannot be Displayed", "Page Cannot be Displayed");

    addOption(document.drop_list.SubCat,"Cannot start listed training", "Cannot start listed training");

    addOption(document.drop_list.SubCat,"Remove Learning", "Remove Learning");
    }


    if(document.drop_list.Category.value == 'MACs'){
    addOption(document.drop_list.SubCat,"SP not listed", "SP not listed");
    }


    if(document.drop_list.Category.value == 'Marlin'){
    addOption(document.drop_list.SubCat,"123 Error", "123 Error");

    addOption(document.drop_list.SubCat,"Server Error", "Server Error");

    addOption(document.drop_list.SubCat,"Invalid Password", "Invalid Password", "");

    addOption(document.drop_list.SubCat,"Rights", "Rights", "");

    addOption(document.drop_list.SubCat,"Disabled", "Disabled", "");

    addOption(document.drop_list.SubCat,"Other", "Other", "");
    }


    if(document.drop_list.Category.value == 'Secure'){
    addOption(document.drop_list.SubCat,"Secure 1", "Secure 1");

    addOption(document.drop_list.SubCat,"Request Replacement", "Request Replacement");

    addOption(document.drop_list.SubCat,"Unalbe to login", "Unalbe to login");

    addOption(document.drop_list.SubCat,"Bind/Unbind", "Bind/Unbind", "");
    }


    if(document.drop_list.Category.value == 'Sheer'){
    addOption(document.drop_list.SubCat,"Invalid Password", "Invalid Password");

    addOption(document.drop_list.SubCat,"No Login", "No Login");
    ;
    }

    }
    //////////////////

    function removeAllOptions(selectbox)
    {
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
    //selectbox.options.remove(i);
    selectbox.remove(i);
    }
    }


    function addOption(selectbox, value, text )
    {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;

    selectbox.options.add(optn);
    }


    HTML
    ---------
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <head>
    <title>Tkat</title>
    <script language="javascript" src="list.js"></script>
    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"

    onload="fillCategory();">

    <FORM name="drop_list" action="postnew.asp" method="POST" >
    <table>

    <tr>
    <td>
    <b>Tools:</b>
    </td>

    <td>
    <SELECT NAME="Category" onChange="SelectSubCat();" >
    <Option value="">Select Category:</option>
    </SELECT>&nbsp;
    </tr>
    </td>

    <tr>
    <td>&nbsp;
    </tr>
    </td>

    <tr>
    <td>
    <b>Error:</b>
    </td>

    <td>
    <SELECT id="SubCat" NAME="Subcat">
    <Option value="">Select Category:</option>
    </tr>
    </td>
    </SELECT>
    </form>
    </body>
    </html>

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    sway2721 -

    The onchange event:

    Code:
    onchange="if (this.selectedIndex==2){this.form['box'].style.visibility='visible'}else {this.form['box'].style.visibility='hidden'};"
    can be added to:

    HTML Code:
    <SELECT id="SubCat" NAME="Subcat">
    <Option value="">Select Category:</option>
    </tr>
    </td>
    </SELECT>
    depending upon what you are trying to do. If the box's designation (form parent and name*) and the option's selectedIndex that should reveal it are constant no matter how the select is populated, the onchange event may be hard coded to the select.

    If all of this stuff is subject to change, you could assign the onchange event to the select on the same basis as you are populating it, ex:

    Code:
    if(document.drop_list.Category.value == 'AAA'){
    addOption(document.drop_list.SubCat,"Invalid Password", "Invalid Password");
    document.getElementById('SubCat').onchange=function(){
    if (this.selectedIndex==1)
    this.form['box'].style.visibility='visible';
    else
    this.form['box'].style.visibility='hidden';
    };
    }
    The red parts are the things you would want to customize for each possible document.drop_list.Category.value and you might even want to add to the code (gray) of the function assignment (green).

    *The text box could be accessed via its id:

    Code:
    document.getElementById('BOX_ID').style
    instead of:

    Code:
    this.form['BOX_NAME'].style
    if you prefer.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •