Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    34
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Passing a value from a dropdownlist to a javascript function to perform Ajax

    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.

    HTML

    Code:
      <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>
                    </asp:DropDownList>
                </div>
    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

    Code:
    function GetTeamUsersByTeamID(field) {
    
        FieldElement = document.getElementById(field);
        destElement.value = FieldElement(FieldElement.selectedIndex).value;
        getUserTeamProperties(document.getElementById(field).value);
    }
    
    function GetTeamUserProperties(intTeamID) {
        ////USE AJAX TO GET THE USER TEAM PROPERTIES
    
        var requestUrl = "AJAX/GetTeamUserProperties.aspx?TeamID=" + intTeamID;
        xmlHttp = GetXmlHttpObject();
    
        if (xmlHttp == null) {
            alert("Your browser does not support AJAX!");
            return;
        }
        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
            xmlHttp.send(null);
        }
    
    }
    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,

    Thanks
    Last edited by Scott.Atkinson; 09-15-2011 at 09:35 AM.

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    34
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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;
    alert(SelectedVal);
    }

    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?
    Last edited by Scott.Atkinson; 09-15-2011 at 11:15 AM.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    34
    Thanks
    7
    Thanked 0 Times in 0 Posts
    No Worries sorted it now got there eventually


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •