I've written a small asp function that query's my database and returns data. I've tested the function and it does return the data correctly.

I'm trying to figure out how I can then take that data and store it into my javascript array. I have this below but I can't figure out how to get the data there.

<script type="text/javascript">
    $(function(){
        var availableTags = [];

        $("input[name='name_search']").change(function() {
            if($(this).val == "First Name")
            {
                availableTags.push = <%= GetEmpFName() %>
            } else {
                availableTags.push = <%= GetEmpLName() %>
            }
        });
    });
</script>

If the ASP function GetEmpFName and GetEmpLName are producing strings, then I would try...

if($(this).val == "First Name")
{
   availableTags.push = "<%= GetEmpFName() %>";
} else {
   availableTags.push = "<%= GetEmpLName() %>";
}

These are my two functions. Are they formated correctly?

<%    
    function GetEmpFName()
            Set rsEmp1 = Server.CreateObject("ADODB.Recordset")
            SQLemp1 = "Select ID, Name_First, Name_Last from tbl_people WHERE active=1 ORDER BY Name_First ASC"
            rsEmp1.open SQLemp1, conn

            While Not rsEmp1.EOF
                Response.Write(rsEmp1.Fields(1) + " " + rsEmp1.Fields(2))
                rsEmp1.MoveNext
            Wend

            rsEmp1.close()
        end function

        function GetEmpLName()
            Set rsEmp2 = Server.CreateObject("ADODB.Recordset")
            SQLemp2 = "Select ID, Name_First, Name_Last from tbl_people WHERE active=1 ORDER BY Name_First ASC"
            rsEmp2.open SQLemp1, conn

            While Not rsEmp2.EOF
                Response.Write(rsEmp2.Fields(2) + ", " + rsEmp2.Fields(1))
                rsEmp2.MoveNext
            Wend

            rsEmp2.close()
        end function
%>     

I don't see anything that stands out. You said the functions were working? You can test them by creating a new page with nothing other than the functions and the asp code nuggets that call them. If they work, move on to troubleshooting your javascript.

What you can do there is test you javascript by passing simple string values instead of that ASP code nugget. If it works and you asp functions work, they should work together.

Not safe because you are using response.write in your functions.
The server-side code processes before the render.
you should do something like this:

function GetEmpFName()
            result=""
            Set rsEmp1 = Server.CreateObject("ADODB.Recordset")
            SQLemp1 = "Select ID, Name_First, Name_Last from tbl_people WHERE active=1 ORDER BY Name_First ASC"
            rsEmp1.open SQLemp1, conn
            While Not rsEmp1.EOF
                result=result & rsEmp1.Fields(1) + " " + rsEmp1.Fields(2) 'did you miss a comma here?
                rsEmp1.MoveNext
            Wend
            rsEmp1.close()
            GetEmpFName=result
        end function
        function GetEmpLName()
            result=""
            Set rsEmp2 = Server.CreateObject("ADODB.Recordset")
            SQLemp2 = "Select ID, Name_First, Name_Last from tbl_people WHERE active=1 ORDER BY Name_First ASC"
            rsEmp2.open SQLemp1, conn
            While Not rsEmp2.EOF
                result=result&rsEmp2.Fields(2) + ", " + rsEmp2.Fields(1)
                rsEmp2.MoveNext
            Wend
            rsEmp2.close()
            GetEmpLName=result
        end function

You should also probably write a vbscript escape routine for javascript characters.

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.