469,889 Members | 1,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

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 1515
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Merdaad | last post: by
reply views Thread by Mythran | last post: by
3 posts views Thread by John Walker | last post: by
3 posts views Thread by Jeff User | last post: by
1 post views Thread by abTech | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.