473,388 Members | 1,383 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,388 software developers and data experts.

Drop Down List not returning selectedIndex

I have a problem I placed a DropDown list control on my .NET page. I do not
want to perform a postback when something is selected. When I want to get
what was selected in the Client Script I do not get anything in the
selectedIndex property in the client script. Is there any way for me the get
the value in the text portion of the dropdown list in client script? I tried
the value property but that does not give me anything...

thanks
Nov 19 '05 #1
3 1672
On Thu, 07 Apr 2005 12:53:09 -0500, Angel
<An***@discussions.microsoft.com> wrote:
I have a problem I placed a DropDown list control on my .NET page. I do
not
want to perform a postback when something is selected. When I want to get
what was selected in the Client Script I do not get anything in the
selectedIndex property in the client script. Is there any way for me the
get
the value in the text portion of the dropdown list in client script? I
tried
the value property but that does not give me anything...

thanks


There's an options property on the dropdown object. An example of how to
set the text of an option:

function changeText()
{
var x=document.getElementById("mySelect");
x.options[x.selectedIndex].text="Melon";
}

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
Unfortunately, because the control is not performing a postback the
selectedIndex never changes eventhough I change the value in the control. On
the selectedIndex is always -1 eventhough I selected a new value from the
dropdown list... Trust me I used the options array to get the value selected,
but because the selectedIndex is -1 I do not get a value...

thanks...

"Craig Deelsnyder" wrote:
On Thu, 07 Apr 2005 12:53:09 -0500, Angel
<An***@discussions.microsoft.com> wrote:
I have a problem I placed a DropDown list control on my .NET page. I do
not
want to perform a postback when something is selected. When I want to get
what was selected in the Client Script I do not get anything in the
selectedIndex property in the client script. Is there any way for me the
get
the value in the text portion of the dropdown list in client script? I
tried
the value property but that does not give me anything...

thanks


There's an options property on the dropdown object. An example of how to
set the text of an option:

function changeText()
{
var x=document.getElementById("mySelect");
x.options[x.selectedIndex].text="Melon";
}

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 19 '05 #3
On Thu, 07 Apr 2005 15:23:08 -0500, Angel
<An***@discussions.microsoft.com> wrote:
Unfortunately, because the control is not performing a postback the
selectedIndex never changes eventhough I change the value in the
control. On
the selectedIndex is always -1 eventhough I selected a new value from the
dropdown list... Trust me I used the options array to get the value
selected,
but because the selectedIndex is -1 I do not get a value...

thanks...

"Craig Deelsnyder" wrote:
On Thu, 07 Apr 2005 12:53:09 -0500, Angel
<An***@discussions.microsoft.com> wrote:
> I have a problem I placed a DropDown list control on my .NET page. I

do
> not
> want to perform a postback when something is selected. When I want to

get
> what was selected in the Client Script I do not get anything in the
> selectedIndex property in the client script. Is there any way for me

the
> get
> the value in the text portion of the dropdown list in client script? I
> tried
> the value property but that does not give me anything...
>
> thanks


There's an options property on the dropdown object. An example of how
to
set the text of an option:

function changeText()
{
var x=document.getElementById("mySelect");
x.options[x.selectedIndex].text="Melon";
}

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Hmmm, all you're wanting is to access the selected index; this example
works for me, click the button it shows the currently selected index on
the client-side (create a file called SelectedIndex.aspx, here's the code):

<%@ Page Language="C#" %>
<HTML>
<HEAD>
<script language="javascript">
function CheckVals()
{
var x = document.getElementById("mySelect");
alert (x.selectedIndex);
}
</script>
</HEAD>
<body>
<form id="form1" runat="server" action="SelectedIndex.aspx"
method="post">
<asp:DropDownList id="mySelect" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3" Selected="True">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList>
<input type="button" id="button1" onclick="CheckVals();"
value="selIndex"/>
</form>
</body>
</HTML>
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #4

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

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
4
by: Merdaad | last post by:
My drop down list is populated from a static array in my codebehind (c#) code. I set the selected index based on some known values(from DB), when the screen shows up, dropdown list shows that the...
3
by: excel_hari | last post by:
Hi, I couldnt locate a Classic ASP group hence posting here. One of my colleagues has designed an intranet site and one of the pages has a drop-down box with close to 300 options. I want to...
0
by: Mythran | last post by:
I wrote an editor for a web control that allows it to list all controls on a page in a drop down box in the property grid. In the EditValue method, I have the following (not all the code, but most...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
3
by: Jeff User | last post by:
Greeting I built asp.net (V1.1) page. I want to use this button to reset SelectedIndex=0 on several drop down lists. However, I do not want to post back to server. The point is to avoid the...
0
by: jaeden99 | last post by:
I have a two drop down list box. The first contains district name(district id is the value) and the the second will contain the user name based on the district selected in the first drop down list....
1
by: abTech | last post by:
Have struggled a lot to get a filtered drop down in the normal html and that too editable ... i have used table like auto-completion etc ... This is the simplest solution for a filtered drop down ...
3
by: Hanoodah | last post by:
Good morning all, Please I need help in a form that I have designed to fill user information. This form needs two drop-down list about specific date, one about contract date, and the other about...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.