Iv been looking at this all morning and for some reason unknown to me i cant figure it out, i have a ASP:DROPDOWNLIST on my HTML page where it has 3 selection options each have a value 1,2,214 as seen below
the item 214 is the one im using for testing purposes i want to be able to select that, which calls a javascript function GetTeamUsersByTeamID();but i have tried everything i can think of, but i keep getting this stupid error message "Object Expected"Heres
the javascript
once i have got this working the ID of the selected item will be passed to a ajax call which will connect to SQL and return all the users that are allowcatedwith the Team they have selected from the drop down list box.please help me as im banging my head
again a brick wall at the moment.
HTML
<div class="RightBoxPopUpBussinessAnalyst">
<asp:DropDownList ID="cmbBAAllocatedTeam" runat="server" onchange="GetTeamUsersByTeamID('MainDisplayContentChange_cmbBAAllocatedTeam');">
<asp:ListItem value="1">BA</asp:ListItem>
<asp:ListItem Value="2">Lansa Davelopment</asp:ListItem>
<asp:ListItem value="214">.Net</asp:ListItem>
</asp:DropDownList>
</div>
Javascript
function GetTeamUsersByTeamID(field)
{
var e = document.getElementById('field'); // select element
If you have a DropDownList control like so:
<asp:DropDownList ID="mycontrol" runat="server"></asp:DropDownList>
and you want to get it's selected value in JavaScript, do it like so:
var control = document.getElementById('<%= mycontrol.ClientID %>');
var selectedvalue = control.options[control.selectedIndex].value;
Babasaheb Kale
Mark as Answer, if the post helped you...
Visit My Blog
iv just tried that and yet object expected! this javascript function is not on the html page, its on a external js folder which i have declared at the top of the html page...
But yet it still doesnt work....it feels like and sounds like that it wants a object and as im not passing it a object thats why i get the "object
Expected"
because originally i was passing it an opbject now iv removed that i think it still remembers the object....if that makes any sense at all?
As a long-shot, try removing the semi-colon ";" after your javascript call in the 'onchange' property.
And what exactly does your javascript and html look like now? Your initial html call and the javascript don't look right. Here's what I would expect would work:
<script type ... blah ...>
Function doSomething()
{
var value = document.getElementById("someID").options[document.getElementById("someID").selectedIndex].value;
//do something with the value
}
</script>
<asp:dropdownlist id="someID" onchange="doSomething()">
...
...
</asp:dropdownlist>
Harrison.Sco...
Member
331 Points
456 Posts
Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 11:23 AM|LINK
Hi All,
Iv been looking at this all morning and for some reason unknown to me i cant figure it out, i have a ASP:DROPDOWNLIST on my HTML page where it has 3 selection options each have a value 1,2,214 as seen below
the item 214 is the one im using for testing purposes i want to be able to select that, which calls a javascript function GetTeamUsersByTeamID();but i have tried everything i can think of, but i keep getting this stupid error message "Object Expected"Heres the javascript
once i have got this working the ID of the selected item will be passed to a ajax call which will connect to SQL and return all the users that are allowcatedwith the Team they have selected from the drop down list box.please help me as im banging my head again a brick wall at the moment.
HTML <div class="RightBoxPopUpBussinessAnalyst"> <asp:DropDownList ID="cmbBAAllocatedTeam" runat="server" onchange="GetTeamUsersByTeamID('MainDisplayContentChange_cmbBAAllocatedTeam');"> <asp:ListItem value="1">BA</asp:ListItem> <asp:ListItem Value="2">Lansa Davelopment</asp:ListItem> <asp:ListItem value="214">.Net</asp:ListItem> </asp:DropDownList> </div> Javascript function GetTeamUsersByTeamID(field){var e = document.getElementById('field'); // select elementasteranup
All-Star
30184 Points
4906 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 11:27 AM|LINK
Hi,
Check these posts-
http://forums.asp.net/p/1702540/4519896.aspx/1?Re+gridview+asyn+post+back+without+ajax+updatepanel
http://forums.asp.net/p/1717977/4587810.aspx/1?Re+JQuery+AJAX+call+to+page+method+not+working
http://forums.asp.net/p/1673883/4388192.aspx/1?Re+drop+down+list+selected+value
http://forums.asp.net/p/1652538/4301074.aspx#4301074
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Raigad
Contributor
5129 Points
956 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 11:30 AM|LINK
Hi do like this
If you have a DropDownList control like so:
<asp:DropDownList ID="mycontrol" runat="server"></asp:DropDownList>
and you want to get it's selected value in JavaScript, do it like so:
var control = document.getElementById('<%= mycontrol.ClientID %>');
var selectedvalue = control.options[control.selectedIndex].value;
Mark as Answer, if the post helped you...
Visit My Blog
Harrison.Sco...
Member
331 Points
456 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 11:44 AM|LINK
Hello i have tried that so my javascript now looks like this
function GetTeamUsersByTeamID()
{
var control = document.getElementById('<%= cmbBAAllocatedTeam.ClientID %>');
var selectedvalue = control.options[control.selectedIndex].value;
alert(selectedvalue)
}
Html looks like below and yet i still get the error "object expected" :(
<div class="RightBoxPopUpBussinessAnalyst"> <asp:DropDownList ID="cmbBAAllocatedTeam" runat="server" onchange="GetTeamUsersByTeamID();"> <asp:ListItem value="1">BA</asp:ListItem> <asp:ListItem Value="2">Lansa Davelopment</asp:ListItem> <asp:ListItem value="214">.Net</asp:ListItem> </asp:DropDownList>koolprasad
Member
64 Points
26 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 11:55 AM|LINK
document.getElementById("ComboID").value will give you selected value of combo
Harrison.Sco...
Member
331 Points
456 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 12:05 PM|LINK
Hello,
iv just tried that and yet object expected! this javascript function is not on the html page, its on a external js folder which i have declared at the top of the html page...
i feel like banging my head against a wall.
Raigad
Contributor
5129 Points
956 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 12:10 PM|LINK
put your Js file in head tag
like this
<script language ="Javascript" src="amount.js"></script>
Mark as Answer, if the post helped you...
Visit My Blog
Harrison.Sco...
Member
331 Points
456 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 12:14 PM|LINK
Iv done that already
Top of my html page within my head tag i have
<script type="text/javascript" language="javascript" src="Scripts/AjaxCall.js"></script>
But yet it still doesnt work....it feels like and sounds like that it wants a object and as im not passing it a object thats why i get the "object Expected"
because originally i was passing it an opbject now iv removed that i think it still remembers the object....if that makes any sense at all?
Bernie West
Member
415 Points
152 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 02:42 PM|LINK
As a long-shot, try removing the semi-colon ";" after your javascript call in the 'onchange' property.
And what exactly does your javascript and html look like now? Your initial html call and the javascript don't look right. Here's what I would expect would work:
<script type ... blah ...> Function doSomething() { var value = document.getElementById("someID").options[document.getElementById("someID").selectedIndex].value; //do something with the value } </script> <asp:dropdownlist id="someID" onchange="doSomething()"> ... ... </asp:dropdownlist>FParikh
Member
142 Points
31 Posts
Re: Getting a value from a ASP:DROPDOWNLIST from javascript
Sep 15, 2011 07:58 PM|LINK
Pass the selected value from aspx page.
HTML <div class="RightBoxPopUpBussinessAnalyst"> <asp:DropDownList ID="cmbBAAllocatedTeam" runat="server" onchange="GetTeamUsersByTeamID(this.value)"> <asp:ListItem value="1">BA</asp:ListItem> <asp:ListItem Value="2">Lansa Davelopment</asp:ListItem> <asp:ListItem value="214">.Net</asp:ListItem> </asp:DropDownList> </div> Javascript (in a seperate file) function GetTeamUsersByTeamID(selectedvalue) { alert(selectedvalue); }