0

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>
3
Contributors
4
Replies
14
Views
3 Years
Discussion Span
Last Post by vsmash
0

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() %>";
}
0

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
%>     

Edited by MaddTechwf: Code formatting

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.