Just want to select the first item of a liste

E

Erwin Moller

Stanislas said:
and don't know how to do.

Please help.

Stan

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
 
S

Stanislas

Thanks a lot, it works

"Erwin Moller"
Stanislas said:
and don't know how to do.

Please help.

Stan

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
 
M

Michael Winter

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].

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top