PDA

Click to See Complete Forum and Search --> : Accessing functions that reside on the server


Oct 3rd, 2000, 04:17 PM
Hi there..... I'm trying to create a table and assign each one of its cells an id on the fly with my asp page. I have created a database that holds a set of generic ids to be used. Here's what my codes look like, maybe you'll understand better:

<%
set RS=server.createobject("adodb.recordset")
sql = "SLECT GenericIDs FROM IDs"
RS.open sql, "TaskManager", adOpenStatic, adLockPessimistic
RS.movefirst

Generated = RS("GenericIDs")
response.write "<table name=mytable border=2 cellspacing=1 width=500>"
response.write"<tr>"
FOR i = 0 to 8
response.write "<td id="&Generated&" onmousedown=AssignColor(Generated) width=30</td>"
RS.movenext
Generated = RS("GenericIDs")
NEXT
response.write "</tr></table>"

SUB AssignColor(id)
received = id
response.write "<script language=vbscript>mytable.cells.item(received).style.backgroundcolor=green </script>"
END SUB
%>


At this point it looks like the function AssignColor cannot be executed properly. The table is displayed but when I click on any cell I get a 'Error on page' response at the bottom left of my browser. I'd be extremely grateful if I could get some help on this one. Thanks in advance.

monte96
Oct 3rd, 2000, 07:42 PM
I'll have a look at a way to do this..

your mixing up the server side code with your client side code. You can't call a sub that's on the server side from client side code (cuz it doesn't exist on the page) and response.write is not available in client side code at all.

monte96
Oct 4th, 2000, 10:21 AM
Try this...


<HTML>
<BODY>
<%
Dim strSQL
Dim Generated

set RS=server.createobject("ADODB.Recordset")
strSQL = "SELECT GenericIDs FROM IDs"
RS.Open strSQL, "TaskManager", adOpenStatic, adLockPessimistic

Generated = RS.Fields("GenericIDs")
response.write "<table name=mytable border=2 cellspacing=1 width=500>"
response.write"<tr>"

Do until rs.EOF
response.write "<td id=" & Generated & " onmousedown=AssignColor(" & Generated & ") width=30></td>"
RS.movenext
Generated = RS.Fields("GenericIDs")
Loop

Response.write "</tr></table>"

%>

<SCRIPT Language="VBScript">
Sub AssignColor(id)
mytable.cells.item(id).style.bgcolor=green
End Sub
</SCRIPT>
</BODY>
</HTML>
<%
rs.close
Set rs = Nothing
'You didn't mention a connection object but you'll want to close and release it as well..