Help needed...

Results 1 to 3 of 3

Thread: Help needed...

  1. #1
    Mats Honkamaa Guest

    Default Help needed...

    I have a function like this:<BR><BR>&#060;%<BR>function svar(alt)<BR><BR>dim conn,RS1,SQL1<BR><BR>Set conn = Server.CreateObject ("ADODB.Connection")<BR>Set RS1 = Server.CreateObject ("ADODB.Recordset")<BR><BR>sPath = Server.MapPath ("../DSN/spelDSN.dsn")<BR> sDSN = "FileDSN=" & sPath & sDSNFile & _<BR> ";DefaultDir=" & sPath & ";"<BR> <BR>Conn.Open sDSN<BR><BR>SQL1 = "INSERT INTO annons_svar(annons_ID, ID, spel_ID, alternativ) VALUES (&#039"&Session("annons_ID")&"&#039,&#039"&Session ("anv_ID")&"&#039, &#039"&Session("s_ID")&"&#039,&#039"&(alt)&"&#039) " <BR><BR> SQL1,conn,1,2<BR><BR>end function<BR>%&#062;<BR><BR>&#039then I have the following code...<BR><BR>&#060;img src="1.jpg" onclick="&#060;%svar(alt1)%&#062;"&#062;<BR>&#060; img src="2.jpg" onclick="&#060;%svar(alt2)%&#062;"&#062;<BR>&#039a nd so on...<BR><BR>The problem is that when I load this page it puts both alt1 and alt2 in the two different rows. I want it to put alt1 when u click picture 1 and alt2 when u click picture 2. <BR>what is wrong?<BR>

  2. #2
    Join Date
    Dec 1969

    Default won't work

    The problem is that you are actually executing this function twice in your ASP as you write the HTML out to the client. What you really want is a function similar to &#039svar&#039 on the<BR>CLIENT SIDE, not the SERVER SIDE. Also, you cannot call a server-side script function like this from a client side click-event. In other words, what you have here will not function properly.<BR><BR>Also, your function needs a bit of work. :) Why are you OPENing a recordset to do an INSERT (not to mention the fact that you create/open a recordset and then just leave it hanging there). Instead, omit the reference to the recordset entirely, e.g.:<BR><BR>function svar(alt)<BR><BR>dim conn,RS1,SQL1<BR><BR>Set conn = Server.CreateObject ("ADODB.Connection")<BR><BR>sPath = Server.MapPath ("../DSN/spelDSN.dsn")<BR>sDSN = "FileDSN=" & sPath & sDSNFile & _<BR>";DefaultDir=" & sPath & ";"<BR><BR>Conn.Open sDSN<BR><BR>SQL1 = "INSERT INTO annons_svar(annons_ID, ID, spel_ID, alternativ) VALUES (&#039"&Session("annons_ID")&"&#039,&#039"&Session ("anv_ID")&"&#039, &#039"&Session("s_ID")&"&#039,&#039"&(alt)&"&#039) " <BR><BR>Conn.Execute SQL1<BR>Conn.Close<BR>Set Conn = nothing<BR><BR>end function<BR><BR><BR>Anyway, to fix your problem, you will have to do a server round-trip (calling this click-tracking code) when the user clicks the image. That is really the ONLY way to update the server-side database (you could also look into Remote Scripting from Microsoft, but either way, it&#039s still a trip back to the server!)<BR>

  3. #3
    Mats Honkamaa Guest

    Default RE: won't work

    Thank u.<BR>Since Im a rookie I would really appreciate some code examples or some more information.

Posting Permissions

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