selecting a default option in a drop down list

Discussion in 'Javascript' started by vimal, Oct 4, 2007.

  1. vimal

    vimal Guest

    hi all,

    i am still a learner in javascript

    i have a select tag with options as follows:

    <select>
    <option py:for="mb in range(32,100)">${mb}</option>
    </select>

    which dynamically generates numbers ranging from 32 to 100

    and if i want the list to show the value "50" when the page is loaded
    what should be done

    thanks in advance,
    vimal
    Binary Karma Enterprise
    vimal, Oct 4, 2007
    #1
    1. Advertising

  2. vimal

    RobG Guest

    On Oct 4, 9:53 pm, vimal <> wrote:
    > hi all,
    >
    > i am still a learner in javascript
    >
    > i have a select tag with options as follows:
    >
    > <select>
    > <option py:for="mb in range(32,100)">${mb}</option>
    > </select>
    >
    > which dynamically generates numbers ranging from 32 to 100
    >
    > and if i want the list to show the value "50" when the page is loaded
    > what should be done


    Set the appropriate option element's selected property to true.


    --
    Rob
    RobG, Oct 4, 2007
    #2
    1. Advertising

  3. vimal

    vimal Guest

    On Oct 4, 5:31 pm, RobG <> wrote:
    > On Oct 4, 9:53 pm, vimal <> wrote:
    >
    > > hi all,

    >
    > > i am still a learner in javascript

    >
    > > i have a select tag with options as follows:

    >
    > > <select>
    > > <option py:for="mb in range(32,100)">${mb}</option>
    > > </select>

    >
    > > which dynamically generates numbers ranging from 32 to 100

    >
    > > and if i want the list to show the value "50" when the page is loaded
    > > what should be done

    >
    > Set the appropriate option element's selected property to true.
    >
    > --
    > Rob


    no if we r having a manual entry.....
    like
    <select> or (.selected="true")-->in javascript
    <option>vimal</option>
    <option>sanjay</option>
    <option selected="selected">ajay</option>
    <option>someone</option>
    </select>


    in this case we know the options
    but i want to select the cases i which the options are unknown
    that is they r generated dynamically
    vimal, Oct 4, 2007
    #3
  4. vimal

    RobG Guest

    vimal wrote:
    > On Oct 4, 5:31 pm, RobG <> wrote:
    >> On Oct 4, 9:53 pm, vimal <> wrote:
    >>
    >>> hi all,
    >>> i am still a learner in javascript
    >>> i have a select tag with options as follows:
    >>> <select>
    >>> <option py:for="mb in range(32,100)">${mb}</option>
    >>> </select>
    >>> which dynamically generates numbers ranging from 32 to 100
    >>> and if i want the list to show the value "50" when the page is loaded
    >>> what should be done

    >> Set the appropriate option element's selected property to true.
    >>
    >> --
    >> Rob


    Please don't quote signatures, trim quotes to what you are replying too.

    >
    > no if we r having a manual entry.....


    This is not SMS. Please use reasonable grammar, spelling and punctuation.


    > like
    > <select> or (.selected="true")-->in javascript
    > <option>vimal</option>
    > <option>sanjay</option>
    > <option selected="selected">ajay</option>
    > <option>someone</option>
    > </select>
    >
    >
    > in this case we know the options
    > but i want to select the cases i which the options are unknown
    > that is they r generated dynamically


    If you don't know what option you want to select, it doesn't matter how
    you go about doing it, you don't know which one to select.

    I guess you need to loop through the existing options and whichever ones
    have their selected property set to true, set them to false. Or remove
    them.

    Then use whatever logic appeals to you to set the selected property of
    one or more to true.



    --
    Rob
    "We shall not cease from exploration, and the end of all our
    exploring will be to arrive where we started and know the
    place for the first time." -- T. S. Eliot
    RobG, Oct 4, 2007
    #4
    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. SirPoonga
    Replies:
    2
    Views:
    742
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,001
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    458
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    252
  5. Replies:
    3
    Views:
    275
Loading...

Share This Page