...

View Full Version : Asp - OnClick Event Handler



TennesseeGuy
02-08-2005, 12:46 AM
I am attempting to execute a very simple sql statement based on an onClick event handler. The script processes error free and does everything but call the function the onclick event handler should call. Can anyone look at the script below and let me know what I am doing wrong?

"<td height=""2"" class=""topicdark"" width=""25%""><b><a href=privatesend.asp?method=Topic&mname=" & rs("T_AUTHOR") & " onClick=""call ReportMeNew(Me)"">Send Warning to Member</a></b></td>" & vbNewline & _


Sub ReportMeNew(Link)
sReportSQL = "update from FORUM_TOPICS set T_WARN = T_WARN + 1 " &_
" where T_AUTHOR= " & AuthorID & " and CAT_ID = " & CatID & " and FORUM_ID = " & ForumID & " and TOPIC_ID = " & TopicID
my_Conn.Execute (sReportSQL)
sReportDSQL = "update from FORUM_TOPICS set T_WARNDATE = " & ChkDate(,,true) & "" &_
" where T_AUTHOR= " & AuthorID & " and CAT_ID = " & CatID & " and FORUM_ID = " & ForumID & " and TOPIC_ID = " & TopicID
my_Conn.Execute (sReportDSQL)
End Sub

miranda
02-08-2005, 09:08 AM
You are calling server side code on the refering page with a link to another page. the code onclick event cannot work the way you want because it is looking at another page. You will need to add some client side javascript to call this function and then open the link. Or Change it to a button then using the name attribute of the button you can call the function with an if statement looking to see if the button was clicked. If it isn't supposed to change to a different page then definately go with the button.

ghell
02-08-2005, 01:29 PM
i thought onclick in asp just called client side .. so if it isnt in <script></script> it shouldnt run it.

TennesseeGuy
02-08-2005, 02:49 PM
I do know on Mouse event handlers are no good in asp when attempting to use it to update a db record so I am trying to find an alternative solution. The link is a must because this would require multiple buttons across the page and waste more bandwidth then I could possible care to spend. If anyone can think of an alternative it would be greatly appreciative otherwise I'll keep looking and keep ya'll updated. :thumbsup:

ghell
02-08-2005, 04:20 PM
cant you just pass what you need to the page it is linked to and run it there, if you can get to those pages in more than one way you could do a referer or querystring check.. alternatively you could send to one page for processing then redirect afterwards to the linked page

TennesseeGuy
02-08-2005, 04:44 PM
I can try I suppose....I ain't very good at programming but I'll give it a shot and see if I can figure out how to pass the information onward and call the function there......be back later

miranda
02-08-2005, 05:53 PM
does the link point to a new page or does it point back to the same page?

If it points to a new page move your function to that page and run it from there. If it points back to itself, then make a name attribute to the anchor tag and look for that name attribute in an if statement. put a call to your function inside that if statement. That should solve the problem.

TennesseeGuy
02-09-2005, 02:00 PM
I have redone everything into a popup. Everything works with one slight problem. I would like when someone clicks the popup that the popup closes and the redirected page appears in the original parent window. I thought a simple target=""parent"" would do the trick but that just puts the redirect page into the popup window. Any ideas?

ghell
02-09-2005, 04:35 PM
this is a javascript problem from here but its not too complicated, it will be answered in any good popup tutorial (eg on dynamic drive) but i am far too lazy to look for it and far too out of practice to answer it myself :(
if you dont get any luck here try asking in the javascript section :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum