473,405 Members | 2,167 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,405 software developers and data experts.

Changing selected element in a listbox

I have a form called myform with a listbox called combounit. I have
another listbox on the form called combolevel. When I change value in
combolevel I call a javascript function that does various things. One
thing gives me problems. How do I make it change the element selected
in combounit?

I have tried:

document.myform.combounit.options[0].selected = true;
and
document.myform.combounit.selectedIndex = 0;

but none of them work.

Regards,

Jan Nordgreen

Jun 20 '06 #1
3 2122
document.myform.combounit.selectedIndex = 0;
this should work

damezumari написа:
I have a form called myform with a listbox called combounit. I have
another listbox on the form called combolevel. When I change value in
combolevel I call a javascript function that does various things. One
thing gives me problems. How do I make it change the element selected
in combounit?

I have tried:

document.myform.combounit.options[0].selected = true;
and
document.myform.combounit.selectedIndex = 0;

but none of them work.

Regards,

Jan Nordgreen


Jun 21 '06 #2
I have a form called myform with a listbox called combounit. How do I make
it change the element selected
in combounit?

I have tried:

document.myform.combounit.options[0].selected = true;
and
document.myform.combounit.selectedIndex = 0;

but none of them work.

Regards,

Jan Nordgreen


Try the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Select Animation</title>
<script type="text/javascript">
//<![CDATA[
<!--
var s;
var i = 0;
function test(){
i++;
if (i >= 7) i = 0;
s.selectedIndex = i;

}
window.onload = function(){
s = document.getElementById("myselect");
window.setInterval("test()", 500);
}
//-->
//]]>
</script>
</head>
<body>

<select size="7" id="myselect">
<option value="1" selected>option1</option>
<option value="2">option2</option>
<option value="3">option3</option>
<option value="4">option4</option>
<option value="5">option5</option>
<option value="6">option6</option>
<option value="7">option7</option>
</select>

</body>
</html>
Jun 21 '06 #3
Thank you chonny and Marc!

It did not work for me because I used

<select size="7" name="myselect">

instead of

<select size="7" id="myselect">

Marc, I tried out your code. Very convincing! :)

Regards,

Jan Nordgreen

Jun 21 '06 #4

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

Similar topics

2
by: Geir Baardsen | last post by:
Hi! From a listbox I'd like to send only selected items to a report. Items will include: OrderNr,Date,EmployeeNr from tblOrders ZipCode,City from tblZipCodes Name,Adr,ZipID from...
2
by: Luca | last post by:
Hello, I'm using a windows form in which there is a standard ListBox control. I want to add/remove objects from the ArrayList associated to the ListBox, and I want the ListBox immediately shows...
4
by: KK | last post by:
Hi All... For my purpose, I need to handle listbox selection changed event.I must be notified before changing occurs and after.After I can handle using SelectedIndexChanged event.Is there anyway...
2
by: Alpha | last post by:
I have a window application. On one of the form, there is a listbox and a few combox. The lstSchItem has a dataview as a datasource. The comboxes are bind to its selected value but through the...
3
by: Vijay | last post by:
Hi, Iam new to VC++6.0. I want to display selected item of the ListBox in a MessageBox. I know for experience ppl it must be a kids play but for me who had worked in C# and VB, it seems to be...
1
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
2
by: Greg | last post by:
I have a listbox inside of a DetailsView. There are three departments to choose from, Corporate, Group, Vacation. The listbox is set to SelectionMode="multiple". I think I have this loop setup...
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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 projectplanning, 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.