473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Just want to select the first item of a liste

and don't know how to do.

Please help.

Stan

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

objSelect = top.document.getElementById(strIdSelect);
objSelet ???
Jul 20 '05 #1
3 1339
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
Jul 20 '05 #2
Thanks a lot, it works

"Erwin Moller"
<si******************************************@spam yourself.com> a écrit dans
le message de news:40*********************@news.xs4all.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

Jul 20 '05 #3
On Thu, 22 Jan 2004 13:24:33 +0100, Stanislas <sr******@intertek.fr> 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
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alexandre Laplante | last post by:
Est-il possible en javascript de modifier les OPTION d'une balise SELECT a partir d'un autre..? Donc la selection d'un premier choix changera la liste du deuxieme. Merci Alex... Is this...
1
by: Raghuram Banda | last post by:
Hi All, Can any one please look into the following code and tell me where I went wrong <html> <head> <script language="JavaScript"> function transferItem(srcId, destId) { var destObj =...
4
by: sakieboy | last post by:
I currently have a datagrid with several columns. The first column in the DataGrid is a HyperLinkColumn. When I select a row, I would like for this HyperlinkColumn to fire. I have the mouseover...
2
by: Andrew Lias | last post by:
Let us say that I have a table with two sets of values as such: Item Extension --- ---- 100023 1 100025 1 100025 2 100028 1 100029 1 100029 2
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
5
by: Bubba | last post by:
I have a dynamic pulldown list (ASP with javascript) that when a user picks a state, the corresponding counties for that state appear in a dynamic second pulldown list. When I submit the form, the...
17
vikas251074
by: vikas251074 | last post by:
I have create form as below - <table> <tr> <td align="right">VLAN Name : </td> <td> <select name="vlan_name" style="width:150px "> <% ...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.