Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Just want to select the first item of a liste

Reply
Thread Tools

Just want to select the first item of a liste

 
 
Stanislas
Guest
Posts: n/a
 
      01-22-2004
and don't know how to do.

Please help.

Stan

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

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


 
Reply With Quote
 
 
 
 
Erwin Moller
Guest
Posts: n/a
 
      01-22-2004
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
 
Reply With Quote
 
 
 
 
Stanislas
Guest
Posts: n/a
 
      01-22-2004
Thanks a lot, it works

"Erwin Moller"
<since_humans_read_this_I_am_spammed_too_much@spam yourself.com> a écrit dans
le message de news:400fc4f3$0$314$(E-Mail Removed)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



 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      01-22-2004
On Thu, 22 Jan 2004 13:24:33 +0100, Stanislas <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)d (replace ".invalid" with ".uk" to reply)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
generating a liste of characters Yves Dorfsman Python 7 12-05-2008 01:56 PM
Can get to Google and search but can't open any of the sites liste =?Utf-8?B?UkNC?= Wireless Networking 1 11-30-2006 01:51 AM
select box - using refresh to select same item twice entfred@hotmail.com Javascript 2 07-25-2006 11:54 PM
Photoshop-CS - Liste mit *allen* Neuheiten? Henrik2000 Digital Photography 3 01-07-2004 06:31 PM
How do I select item in <SELECT> K. Lobe ASP General 3 07-02-2003 06:40 PM



Advertisments