Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

question

anthony78anthony78 Posts: 18Member
Hi all,

I have 2 programming problems hope someone can help me. (solutions in javascript or html is fine with me).

i have 2 html

Comments

  • lillulillu Posts: 308Member
    Hi,

    There are many ways to do this, so this is just one of them.

    I roughly explain what it does:

    1. Code one of the options (eg. Fruit - Apple, Pear) into html so that it will always be displayed when the page is loaded.
    2. In the function, create the object you want to change dynamically
    sel = the second list box, where the things change
    3. Set sel's options' length to zero (very important, or it will grow endlessly
    4. Create Option arrays with your choices to appear, you will reference them by their value handle




    function setOptions(o)
    {
    var sel = document.myform.option2;

    sel.options.length = 0;

    if (o == "1")
    {
    sel.options[sel.options.length] = new Option('Apple');
    sel.options[sel.options.length] = new Option('Pear');
    }
    if (o == "2")
    {
    sel.options[sel.options.length] = new Option('Carrot');
    sel.options[sel.options.length] = new Option('Potatoe');
    }
    if (o == "3")
    {
    sel.options[sel.options.length] = new Option('Chicken');
    sel.options[sel.options.length] = new Option('Fish');
    }
    }
















    Basically, this is it. If you have any questions feel free to ask them.

    Lillu
    : Hi all,
    :
    : I have 2 programming problems hope someone can help me. (solutions in javascript or html is fine with me).
    :
    : i have 2 html
Sign In or Register to comment.