Drop Down List not returning selectedIndex

G

Guest

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
 
C

Craig Deelsnyder

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";
}
 
G

Guest

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 said:
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";
}
 
C

Craig Deelsnyder

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 said:
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";
}

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top