Howdy, Stranger!

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

Categories

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 tags, let name them A and B

Now suppose A tags got d, f, g

now suppose B tag is 'dependant' on A, example
if in A d is selected, B will have x, y , z
if in A e is selected, B will have H, i, j, k, l (notice the numuber of options difference)

How do i achieve this? i know one of the methods is to display the highest num of selection options(in this case, 5) and blank out(set to null) the values of the option when different option in A is selected but that would look unpresentable on the page.

Once the above problem is solve, then another question is related to above, suppose

apple
orange
pear

how do i change the "apple", "orange", and "pear" when the option changes??

Forgive my English and Thanks in advance to those who will help me.

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');
    }
    }






    Fruit
    Vegetable
    Meat






    Apple
    Pear






    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 tags, let name them A and B
    :
    : Now suppose A tags got d, f, g
    :
    : now suppose B tag is 'dependant' on A, example
    : if in A d is selected, B will have x, y , z
    : if in A e is selected, B will have H, i, j, k, l (notice the numuber of options difference)
    :
    : How do i achieve this? i know one of the methods is to display the highest num of selection options(in this case, 5) and blank out(set to null) the values of the option when different option in A is selected but that would look unpresentable on the page.
    :
    : Once the above problem is solve, then another question is related to above, suppose
    :
    : apple
    : orange
    : pear
    :
    : how do i change the "apple", "orange", and "pear" when the option changes??
    :
    : Forgive my English and Thanks in advance to those who will help me.
    :

Sign In or Register to comment.