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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2004
    Location
    Manitoba, CANADA
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    disable cascading selects

    There are two drop down menus - the first has two options - Province and State. The second select changes to show the corresponding provinces/states. I need to disable the second select when Province is selected in the first select (basically, when the page loads). I have tried

    if(document.form6.choose_category[0].selected==true)
    {
    document.form6.the_examples.disabled=true)
    }

    and have changed it around a couple of times but just seem to be missing something. If anyone can offer assistance, I would appreciate same. Thanks!!

    Here is the code:


    <html>
    <script language="javascript">

    var Province = new Array("British Columbia","Alberta","Saskatchewan","Manitoba","Ontario",
    "Quebec","New Brunswick","Newfoundland","Prince Edward Island","Nova Scotia")
    var States = new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut",
    "Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Lou isiana","Maine",
    "Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nev ada","New Hampshire",
    "New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island",
    "South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia",
    "Wisconsin","Wyoming");

    function swapOptions(the_array_name)
    {
    var numbers_select = document.form6.the_examples;
    document.form6.the_examples.length=50;
    var the_array = eval(the_array_name);
    setOptionText(document.form6.the_examples, the_array);
    }

    function setOptionText(the_select, the_array)
    {
    for (loop=0; loop < the_select.options.length; loop++)
    {
    the_select.options[loop].text = the_array[loop];
    }
    }

    function disabled1(){
    if(document.form6.Province[0].selected==true)
    { document.form6.the_examples.disabled==true

    }
    }
    </script>
    <body>
    <form name="form6">
    <p align=top>
    <select name="choose_category"
    onChange="swapOptions(document.form6.choose_category.options[selectedIndex].text);">
    <option selected>Province
    <option>States
    </select>

    <select name="the_examples">
    <option>British Columbia
    <option>Alberta
    <option>Saskatchewan
    <option>Manitoba
    <option>Ontario
    <option>Quebec
    <option>New Brunswick
    <option>Newfoundland
    <option>Prince Edward Island
    <option>Nova Scotia

    </select>
    </form>

    </html>


    Thanks Again!!!!!

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try:
    if(document.form6.choose_category.selectedIndex==0)

    .....Willy

  • #3
    New Coder
    Join Date
    Feb 2004
    Location
    Manitoba, CANADA
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That did not work but you gave me an idea and I tried this:

    if(document.form6.choose_category.options[0].selected==true)

    and now it works. Thanks very much!!!


  •  

    Posting Permissions

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