View Full Version : Passing a value from a dropdownlist to a javascript function to perform Ajax

09-15-2011, 10:29 AM
Hi All,

i have a adp:dropdownlist which holds text and its value im having trouble passing the selected value to a javascript function which then in turn will perform a ajax call that will go to the SQL and return all user that have the TeamID im passing in.


<div class="RightBoxPopUpBussinessAnalyst">
<asp:DropDownList ID="cmbBAAllocatedTeam" runat="server" AutoPostBack="true" onchange="javascript:GetTeamUsersByTeamID('MainDisplayContentChange_DropDownList5')">
<asp:ListItem>Business Analyst</asp:ListItem>
<asp:ListItem>Lansa Davelopment</asp:ListItem>
<asp:ListItem Value="214">.Net</asp:ListItem>

the last listitem is the one im using for testing and im trying to call the function of a "onchange event" which you can also see in the above html

the javascript looks like this

function GetTeamUsersByTeamID(field) {

FieldElement = document.getElementById(field);
destElement.value = FieldElement(FieldElement.selectedIndex).value;

function GetTeamUserProperties(intTeamID) {

var requestUrl = "AJAX/GetTeamUserProperties.aspx?TeamID=" + intTeamID;
xmlHttp = GetXmlHttpObject();

if (xmlHttp == null) {
alert("Your browser does not support AJAX!");
else {
//Setting the event handler for the response
xmlHttp.onreadystatechange = UserTeamPropertiesReturned;
//Initializes the request object with GET (METHOD of posting),
xmlHttp.open("GET", requestUrl, true);
//Sends the request to server


the first function it calls is GetTeamUsersByTeamID which then finds out what value which is the TeamID of 214 that has been selected and then calls the second function and passed in that value which starts the ajax call but on the first line of GetTeamUsersByTeamID i get 'value is underfined' and im sure what im doing wrong here.....im new to javascript so please bare with me :(

Hope someone can help and i look forward to your reply,


09-15-2011, 11:04 AM
iv tried this as still get the error 'value' is underfined?

function GetTeamUsersByTeamID(field)
var IndexValue = $get('<%=field.ClientID %>').selectedIndex;
var SelectedVal = $get('<%=field.ClientID %>').options[IndexValue].value;

im trying to make the javascript function global so it can be called in mulitple places saves having to replicate the same script for each drop down that requires the users for a team etc.....

i have managed to get it working to an extent with the above javascript function but it now says object expected on var indexvalue when i break and hover over field it has the name of the dropdownlist box in there...can someone shed any light on to what this might be?

09-15-2011, 08:19 PM
No Worries sorted it now :) got there eventually :)