Hello,
I've also posted this on the general ajax forum, but thought this might be a better place for it.
I'm trying to do my first ajax page, and almost all the examples I'm seeing are referencing the actual id of their asp control in the javascript function. If you look at the code below you see that I'm trying to referece the cityList dropdown from my javascript, but I keep getting an 'object required' error on the page because, as we all know, when the page renders, the <asp:dropdownlist will be rendered as a <select tag with an autogenerated id that might be called 'ctl00_ContentColumn_cityList' or something like that. How do I reference that control by it's actual name?
web form code
javascript
I've also posted this on the general ajax forum, but thought this might be a better place for it.
I'm trying to do my first ajax page, and almost all the examples I'm seeing are referencing the actual id of their asp control in the javascript function. If you look at the code below you see that I'm trying to referece the cityList dropdown from my javascript, but I keep getting an 'object required' error on the page because, as we all know, when the page renders, the <asp:dropdownlist will be rendered as a <select tag with an autogenerated id that might be called 'ctl00_ContentColumn_cityList' or something like that. How do I reference that control by it's actual name?
web form code
Code:
<td><asp:DropDownList ID="stateList" runat="server" onchange="return StateListOnChange(this)" ></asp:DropDownList></td> <td><asp:DropDownList ID="cityList" runat="server"></asp:DropDownList></td>
javascript
Code:
function ClearAndSetCitiesListItems(StateNode)
{
var cityList = document.getElementById("cityList");
for (var count = cityList.options.length-1; count >-1; count--)
{
cityList.options[count] = null;
}
var cityNodes = StateNode.getElementsByTagName('State');
var textValue;
var optionItem;
//Add new states list to the state combo box.
for (var count = 0; count < cityNodes.length; count++)
{
textValue = GetInnerText(cityNodes[count]);
optionItem = new Option( textValue, textValue, false, false);
cityList.options[cityList.length] = optionItem;
}
}