472,364 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 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 1608
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

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.