Member Avatar for jchoudhury

Sorry for the basic silly question. But I really dont have any idea on solving this. I have ASP controls (One Text Box and One Drop Down List). Now I need to access value property of TextBox as well as SelectedIndex property of dropdown list. This should be as simple as:
for TextBox:

document.getElementById('<%= myControl.ClientID %>').value

for DropDown List:

document.getElementById('<%= myControl.ClientID %>;').selectedindex

But in Visual Studio 2008, while I am writing these codes, it does not work. I can not find any value or selectedindex attribute for the respective control. I am not getting this, because in most forums and tutorials, they suggested in a simple way I mentioned.

Is there any other way or I am just missing something here? Please help me out. Thanks in advance

Member Avatar for stbuchok

Intellesense will not show these values as it can't compile the value of <%=myControl.ClientID%> on the fly as it is server side. Try out the code and use alerts to determine if you are getting what you need.

this is wrong "document.getElementById('<%= myControl.ClientID %>;').selectedindex" remove the ;

1. In your browser, View Source of the served page. Is the source what you expect, with <%= myControl.xxxxx %> directives successfully substituted, and do these ids correspond to those of the element(s) in the HTML?

2. The current value of your <select> menu should be given by :-

var el = document.getElementById('<%= myControl.ClientID %>');
var value = el[el.selectedindex].value;

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.