Just want to select the first item of a liste

Discussion in 'Javascript' started by Stanislas, Jan 22, 2004.

  1. Stanislas

    Stanislas Guest

    and don't know how to do.

    Please help.

    Stan

    -----------------------------------------------

    objSelect = top.document.getElementById(strIdSelect);
    objSelet ???
     
    Stanislas, Jan 22, 2004
    #1
    1. Advertising

  2. Stanislas

    Erwin Moller Guest

    Stanislas wrote:

    > and don't know how to do.
    >
    > Please help.
    >
    > Stan
    >
    > -----------------------------------------------
    >
    > objSelect = top.document.getElementById(strIdSelect);
    > objSelet ???


    Hi Stan,

    ??
    I am not sure what your question is.
    If you are talking about arrays, try this:

    someArray[0] to get the first element.

    If you have a selectbox:

    <form name="myForm">
    <select name="mySelect">
    <option value="testing"> testing
    <option value="Hammil"> P.Hammil
    <option value="Postgres"> Postgres
    </select>
    </form>

    You can get the first element in the selectbox like this:
    firstelement = document.forms["myForm"].mySelect[0];

    The value like this:
    firstelementvalue = document.forms["myForm"].mySelect[0].value;

    And if you want to know which element is chooses, try this:
    selInd = document.forms["myForm"].mySelect.selectedIndex;

    Good luck,
    Regards,
    Erwin Moller
     
    Erwin Moller, Jan 22, 2004
    #2
    1. Advertising

  3. Stanislas

    Stanislas Guest

    Thanks a lot, it works

    "Erwin Moller"
    <> a écrit dans
    le message de news:400fc4f3$0$314$4all.nl...
    > Stanislas wrote:
    >
    > > and don't know how to do.
    > >
    > > Please help.
    > >
    > > Stan
    > >
    > > -----------------------------------------------
    > >
    > > objSelect = top.document.getElementById(strIdSelect);
    > > objSelet ???

    >
    > Hi Stan,
    >
    > ??
    > I am not sure what your question is.
    > If you are talking about arrays, try this:
    >
    > someArray[0] to get the first element.
    >
    > If you have a selectbox:
    >
    > <form name="myForm">
    > <select name="mySelect">
    > <option value="testing"> testing
    > <option value="Hammil"> P.Hammil
    > <option value="Postgres"> Postgres
    > </select>
    > </form>
    >
    > You can get the first element in the selectbox like this:
    > firstelement = document.forms["myForm"].mySelect[0];
    >
    > The value like this:
    > firstelementvalue = document.forms["myForm"].mySelect[0].value;
    >
    > And if you want to know which element is chooses, try this:
    > selInd = document.forms["myForm"].mySelect.selectedIndex;
    >
    > Good luck,
    > Regards,
    > Erwin Moller
     
    Stanislas, Jan 22, 2004
    #3
  4. On Thu, 22 Jan 2004 13:24:33 +0100, Stanislas <> wrote:

    > and don't know how to do.


    In future, please actually include the question in the body of your post,
    even if it's just a copy of the subject[1].

    <snip>
    > objSelect = top.document.getElementById(strIdSelect);
    > objSelet ???


    When you say list, I assume you mean a SELECT element.

    If your list is in a form, like this:

    <form ... name="formName">
    <select ... name="listName">
    ...

    you can reference the list with JavaScript like so:

    document.formName.listName

    To select the first item in the list, you can write:

    document.formName.listName.selectedIndex = 0;

    If your list is not part of a form, you'll need to place an ID on it, like
    this:

    <select ... id="listId">

    and access it thus (I included feature detection):

    var listObject = null;
    if( document.getElementById ) {
    listObject = document.getElementById( 'listId' );
    } else if( document.all ) {
    listObject = document.all[ 'listId' ];
    }
    if( listObject ) {
    listObject.selectedIndex = 0;
    }

    Hope that helps,
    Mike

    [1] Bad clients might not show the entire subject, making it impossible
    for people to understand your question help you.

    --
    Michael Winter
    d (replace ".invalid" with ".uk" to reply)
     
    Michael Winter, Jan 22, 2004
    #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. hypomite
    Replies:
    2
    Views:
    611
    S. Justin Gengo
    Aug 14, 2003
  2. Drulli Rokk
    Replies:
    3
    Views:
    769
    David Andriana
    Oct 1, 2003
  3. Yves Dorfsman

    generating a liste of characters

    Yves Dorfsman, Dec 3, 2008, in forum: Python
    Replies:
    7
    Views:
    315
    Mark Tolonen
    Dec 5, 2008
  4. K. Lobe

    How do I select item in <SELECT>

    K. Lobe, Jul 2, 2003, in forum: ASP General
    Replies:
    3
    Views:
    139
    K. Lobe
    Jul 2, 2003
  5. Bala Ji

    Python mange with liste

    Bala Ji, Dec 28, 2013, in forum: Python
    Replies:
    7
    Views:
    100
    Frank Millman
    Dec 29, 2013
Loading...

Share This Page