button selects an option

Discussion in 'Javascript' started by kain, Oct 12, 2006.

  1. kain

    kain Guest

    hi,
    I've a button, onclick I need to automagically select an option a in
    dropdown box.
    something like:

    <input type="button"
    onclick="document.getElementById('tematismo').selected =
    'appartamenti'" value="Appartamenti" class="button" />

    That's the way to go?

    thanks.
     
    kain, Oct 12, 2006
    #1
    1. Advertising

  2. kain

    Elegie Guest

    kain wrote:

    Hi,

    > I've a button, onclick I need to automagically select an option a in
    > dropdown box.
    > something like:
    >
    > <input type="button"
    > onclick="document.getElementById('tematismo').selected =
    > 'appartamenti'" value="Appartamenti" class="button" />


    Provided your SELECT element has a NAME attribute called "tematismo":
    just put the following in your ONCLICK attribute:

    ---
    selectOptionsByValue(this.form.elements['tematismo'],this.value)
    ---

    ....defining the javascript function as:

    ---
    function selectOptionsByValue(o, v) {
    v=v.toLowerCase();
    for(var opt=o.options, ii=opt.length; ii--;)
    opt[ii].selected=(opt[ii].value.toLowerCase()==v);
    }
    ---


    HTH.
     
    Elegie, Oct 12, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dirk Meusel
    Replies:
    1
    Views:
    3,032
    Dirk Meusel
    Aug 19, 2003
  2. Harry
    Replies:
    1
    Views:
    563
    Ather Ali Shaikh
    Jan 17, 2004
  3. DC Gringo
    Replies:
    2
    Views:
    2,320
    Nikhil Patel
    Feb 26, 2004
  4. Leszek Taratuta
    Replies:
    2
    Views:
    14,477
    Leszek Taratuta
    Aug 12, 2004
  5. Adrienne Boswell
    Replies:
    0
    Views:
    708
    Adrienne Boswell
    Jun 8, 2010
Loading...

Share This Page