473,690 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1690
On Thu, 07 Apr 2005 12:53:09 -0500, Angel
<An***@discussi ons.microsoft.c om> 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.getE lementById("myS elect");
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***@discussi ons.microsoft.c om> 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.getE lementById("myS elect");
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***@discussi ons.microsoft.c om> 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***@discussi ons.microsoft.c om> 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.getE lementById("myS elect");
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.a spx, here's the code):

<%@ Page Language="C#" %>
<HTML>
<HEAD>
<script language="javas cript">
function CheckVals()
{
var x = document.getEle mentById("mySel ect");
alert (x.selectedInde x);
}
</script>
</HEAD>
<body>
<form id="form1" runat="server" action="Selecte dIndex.aspx"
method="post">
<asp:DropDownLi st 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:DropDownLis t>
<input type="button" id="button1" onclick="CheckV als();"
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
6299
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 the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
4
2714
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 the first items is selected and not the one assigned. Please note that if I hardcode the dropdown items inside the .aspx file, everything works fine. Please point me to examples(infopath examples somehow don't show up for me!).
3
3192
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 navigate to the desired option quickly just by typing out the name. For example if I want to choose "Other" (All the options are arranged alhabetically within the Drop-down box) from Drop-down and if I Type "O" then I navigate to first entry with...
0
1035
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 of it): ^snip^ ' Create the listbox to display the control id's. listBox = New ListBox() With listBox .BorderStyle = BorderStyle.None
3
2992
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 the drop down box to go back to what the value was before the user tried to change it, but at that point I will not know what the original value was. Or is there a drop down control "revert" method, or is there any way of knowing what the original...
3
1477
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 round trip. It had an asp:button which would post back to the server when clicked but changed it to an input button to avoid the postback. (If that is not needed,let me know)
0
1462
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. I am trying to code this in vb.net. It is a web based application. I've gotten the district info to load, but I can't figure out how to get the users to load. I've created a stored procedure to get user... Stored procedure info. SELECT...
1
5947
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 <SELECT NAME="drop" id='drop' onkeyup="editOption(arguments, this)" style='width:100px;cursor:text' mode="1"> <option value="0">Default</option> … </SELECT> Mode 0: Filters the list till a valid match is found, if not found then will behave...
3
1893
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 birth date. I am using java script function to display the dates, and use onload() function to set the drop-down list to the current date. I following error used to appear (null or not an object)!! Can any one help me in that? The code: ...
0
8531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8786
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4550
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1952
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.