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