473,624 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting a Specific Option

I need to be able to select a specific option in a select list. This is
what I have:
<select name="mysel">
<option value=""></option>
<option value="1">First </option>
<option value="2" selected>First</option>
<option value="3">First </option>
</select>

But I want to select the first option. Here is my code:

var frm_objs = document.report .elements;
for ( j=0; j<frm_objs.leng th; j++ )
{
if ( frm_objs[j].type=='select-one' )
{
if ( frm_objs[j].name=='mysel' )
{
frm_objs[j].options[0].selected=true;
}
}
}

I think is should select the first ooption but it does not. The default
option 2 remains selected.

Any help is apreciated.

Jul 23 '05 #1
2 2062
mike wrote:
I need to be able to select a specific option in a select list. This is what I have:
<select name="mysel">
<option value=""></option>
<option value="1">First </option>
<option value="2" selected>First</option>
<option value="3">First </option>
</select>

But I want to select the first option. Here is my code:

var frm_objs = document.report .elements;
for ( j=0; j<frm_objs.leng th; j++ )
{
if ( frm_objs[j].type=='select-one' )
{
if ( frm_objs[j].name=='mysel' )
{
frm_objs[j].options[0].selected=true;
}
}
}

I think is should select the first ooption but it does not. The default option 2 remains selected.

Any help is apreciated.


<html>
<head>
<script type="text/javascript">

window.onload = function()
{
var frm_objs = document.report .elements;
for ( j=0, len = frm_objs.length ; j<len; j++ )
{
obj = frm_objs[j];
if ( obj.type=='sele ct-one' //unnecessary
&& obj.name=='myse l' )
{
obj.options[0].selected=true;
}
}
}

</script>
</head>
<body>
<form name="report">
<select name="mysel">
<option value="0">Optio n 0</option>
<option value="1">Optio n 1</option>
<option value="2" selected>Option 2</option>
<option value="3">Optio n 3</option>
</select>
</form>
</body>
</html>

Jul 23 '05 #2
mike wrote:
I need to be able to select a specific option in a select list. This is
what I have:

<snip>

<head>
<script type="text/javascript">
function setselectedinde x(n) {
var m=document.getE lementById('myl ist');
m.selectedIndex = n;
}
</script>
</head>

<body>
<select id='mylist'>
<option value=0>Zero</li>
<option value=1>One</li>
<option value=2>Two</li>
</select>
<br><br>
<input type='button' value='Set SelectedIndex to 0'
onclick="setsel ectedindex(0)"; ><br>
<input type='button' value='Set SelectedIndex to 1'
onclick="setsel ectedindex(1)"; ><br>
<input type='button' value='Set SelectedIndex to 2'
onclick="setsel ectedindex(2)"; ><br>
</body>
Jul 23 '05 #3

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

Similar topics

3
2514
by: Simon G Best | last post by:
Hello! The C++ standard library provides facilities for finding out the sizes (and other such stuff) of numeric types (::std::numeric_limits<>, for example). What I would like to do is to select a type on the basis of its traits. More specifically, I would like to select an unsigned integer type on the basis of the number of bits I need it to have. (This is because there are particularly efficient ways of implementing the Advanced
1
1525
by: newcomer | last post by:
I have a javascript index that is similar to the one in the Windows help. It has a text field that allows the you to type text and it finds the closest item in the list below the text field. The list is simply a select element with options that looks like this: <SELECT> <OPTION VALUE="1">A <OPTION VALUE="2">B <OPTION VALUE="3">C </SELECT>
1
3607
by: jzhang29 | last post by:
I have a JSP page and it contains a dropdown list called Office. What I try to do is: When I select different office from this list, the information of office (address, phone,etc) will be populated in same JSP page. I have a java bean called officeBean that contains all the office information.
4
4715
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student athletes.  I have now learned how to join two different tables in a query so that I might generate a report. Specifically, student athletes at a community college are required to graduate with an AA or AS degree.  Consequently, various steps are in...
2
3648
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code /////////////////////////////////////////////////////////////////////////////////////// <form action="whatever.php" method="post"> <select name="zip_code" onchange="makeRequest('getCity.php?state='+this.form.zip_code.options.value)" multiple="multiple" size="20">
5
22755
by: Mahesh S | last post by:
Hi I would like to write a SQL select statement that would fetch rows numbered 50 to 100. Let me clarify, if i say "fetch first 10 rows only", it returns the first 10 rows from the resultset. how do I get a specific subset of rows from the result set if I give a start and end value. For example, retreiving rows 50 to 100 from the resultset.
1
2027
by: =?ISO-8859-1?Q?Une_B=E9vue?= | last post by:
my xml fragment : <select id='aId'> <option>option 1</option> <option>option 2</option> <option>---?---</option> <option>option n + 1</option> <option>option n + 2</option>
4
2069
by: kang jia | last post by:
hi i am doing mailinglist currently. the code in my first page is like this : : <html> <head> <link rel="stylesheet" type="text/css" href="gallery.css" /> <script language="JavaScript"> <!--
2
1528
by: .nLL | last post by:
got below script, works fine with IE but fails on opera. my js knowledge is very limited and can't find whats wrong with it. ---------------------------------------------- function selectMatching(x) { var S = document.getElementById("mymonth"); var L = S.options.length; for (var i=0; i <= L-1; i++) {
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8631
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.