Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link Onclick event

Status
Not open for further replies.

jgales

Programmer
Mar 7, 2003
14
US
I am attempting to utilize the onclick event for a link. When the link is clicked I am executing a vbscript routine to perfom some database updates. As part of the process I am unable to access the server and application objects. When I specify runat='server' I can access those object but then I am unable to access the window object. The reason I need the window object is because I need to now what the link string is obtained via window.event.srcElement.

Jeff
 
Hi Jeff,

Your running into the classic web development barrier.

To do meaningful web development you must first grasp the concept that when your running "server side" code (ASP code) there is no browser and therefore no DOM objects or HTML elements etc.

Conversely when "client side" code is executing, it is running in a "browser" application which of course is NOT on the Server and therefore has no access to any of the "server side" devices, components, code etc.

does that help?
-pete
 
After making my post I realized that the window object is not available to me. Now when I designate the script as server side I am unable to connect. Here is my code that I am trying to execute. As you can see my code referencing the window object is commented out and I have defaulted idiff=0 to trigger the first if condition. The sql statement does not get executed.

<script language=&quot;vbscript&quot; runat='server'>
sub ImageHits
dim dDate
dim dDate2
dim sSQL
dim CN1
dim iDiff
set CN1 = server.CreateObject(&quot;adodb.connection&quot;)
CN1.Open Application(&quot;ACCPAYWF_ConnectionString&quot;)
' if instr(1, window.event.srcElement,&quot;divaimg2&quot;) > 0 then
' dDate=Mid(window.event.srcElement,instr(1,window.event.srcElement,&quot;20&quot;),8)
' dDate2=mid(dDate,5,2) & &quot;/&quot; & mid(dDate,7,2) & &quot;/&quot; & mid(dDate,1,4)
' iDiff = datediff( &quot;d&quot;, dDate2, now)
' else
iDiff = 0
' end if

if iDiff < 31 then
sSQL=&quot;update ImageCounts set IC_LEVEL30 = IC_LEVEL30 + 1&quot;
else if idiff < 61 then
sSQL=&quot;update ImageCounts set IC_LEVEL60 = IC_LEVEL60 + 1&quot;
else if idiff < 91 then
sSQL=&quot;update ImageCounts set IC_LEVEL930 = IC_LEVEL90 + 1&quot;
else if idiff < 181 then
sSQL=&quot;update ImageCounts set IC_LEVEL180 = IC_LEVEL180 + 1&quot;
else if idiff < 271 then
sSQL=&quot;update ImageCounts set IC_LEVEL270 = IC_LEVEL270 + 1&quot;
else if idiff < 361 then
sSQL=&quot;update ImageCounts set IC_LEVEL360 = IC_LEVEL360 + 1&quot;
else if idiff < 541 then
sSQL=&quot;update ImageCounts set IC_LEVEL540 = IC_LEVEL540 + 1&quot;
else if idiff < 721 then
sSQL=&quot;update ImageCounts set IC_LEVEL720 = IC_LEVEL720 + 1&quot;
else if idiff > 720 then
sSQL=&quot;update ImageCounts set IC_LEVEL720PLUS = IC_LEVEL720PLUS + 1&quot;
end if
end if
end if
end if
end if
end if
end if
end if
end if
CN1.Execute sSQL, 1
CN1.close
set CN1=nothing
end sub
</script>
 
My advice is to run this

Code:
   if  iDiff < 31 then
            sSQL=&quot;update ImageCounts set IC_LEVEL30 = IC_LEVEL30 + 1&quot; 
   end if    
    CN1.Execute  sSQL, 1
    CN1.close
    set CN1=nothing

If that works then your problem is in your nested elseif mess. If it doesn't work then you have a smaller problem to work on.

good luck
-pete
 
No dice...I originally had a case statement which didn't work either. Grasping for straws at this point. Connections and sql execution is pretty basic stuff. I'm getting the feeling that the script is not running at all.
 
>> getting the feeling

My advice,

don't develop software by &quot;feeling&quot;, if you have a suspicion devise a way to confirm it.

If you think the function or code block is not executing do something like this:

Code:
Response.Write &quot;<!-- running this code now -->&quot;

-pete

 
Already done that. No result. As far as the If Else mess goes when using a select case statement cases such as 0 to 30 where recognized. It was having a problem with the 'to'. It looks as though the best way to solve this is to obtain the link string and perform my sql string build in a client side script and then pass the sql string to a server side script to execute the sql.
 
>> I am attempting to utilize the onclick event for a link.
>> When the link is clicked I am executing a vbscript
>> routine to perfom some database updates.

So if i'm following our thread correctly the problem is whatever mechanism you have for this is not working yes?

can you post the code that provides that mechanism?

-pete
 
I performed some additional searches and came upon some info regarding the pageobject. It appears based on the forum I read that I can call a server side script from a client side script using this object. Given that this is totally new for I would like to know if this the way to go? If so, does matter where my server side script resides?

Here is my code at this point, still not working.


<script language=&quot;vbscript&quot; >
sub ImageHits
dim dDate
dim dDate2
dim sSQL
dim iDiff

if instr(1, window.event.srcElement,&quot;divaimg2&quot;) > 0 then
dDate=Mid(window.event.srcElement,instr(1,window.event.srcElement,&quot;20&quot;),8)
dDate2=mid(dDate,5,2) & &quot;/&quot; & mid(dDate,7,2) & &quot;/&quot; & mid(dDate,1,4)
iDiff = datediff( &quot;d&quot;, dDate2, now)
else
iDiff = 721
end if

if iDiff < 31 then
sSQL=&quot;update ImageCounts set IC_LEVEL30 = IC_LEVEL30 + 1&quot;
else if idiff < 61 then
sSQL=&quot;update ImageCounts set IC_LEVEL60 = IC_LEVEL60 + 1&quot;
else if idiff < 91 then
sSQL=&quot;update ImageCounts set IC_LEVEL930 = IC_LEVEL90 + 1&quot;
else if idiff < 181 then
sSQL=&quot;update ImageCounts set IC_LEVEL180 = IC_LEVEL180 + 1&quot;
else if idiff < 271 then
sSQL=&quot;update ImageCounts set IC_LEVEL270 = IC_LEVEL270 + 1&quot;
else if idiff < 361 then
sSQL=&quot;update ImageCounts set IC_LEVEL360 = IC_LEVEL360 + 1&quot;
else if idiff < 541 then
sSQL=&quot;update ImageCounts set IC_LEVEL540 = IC_LEVEL540 + 1&quot;
else if idiff < 721 then
sSQL=&quot;update ImageCounts set IC_LEVEL720 = IC_LEVEL720 + 1&quot;
else if idiff > 720 then
sSQL=&quot;update ImageCounts set IC_LEVEL720PLUS = IC_LEVEL720PLUS + 1&quot;
end if
end if
end if
end if
end if
end if
end if
end if
end if
call result2.execute.testsub( ssql)
end sub
</script>

<script language=&quot;vbscript&quot; runat = server>
sub Testsub(sql)
dim CN
Set CN=Server.CreateObject(&quot;ADODB.Connection&quot;)
CN.Open Application(&quot;accpaywf_connectionstring&quot;)
CN.Execute sql
CN.Close
set CN = nothing
end sub
</script>
<p>&nbsp;</p>
</body>
</html>
 
>> call result2.execute.testsub( ssql)

what is &quot;result2&quot;? That is the first time it shows up in your code.

-pete
 
result2 is the page name which is also the name of the pageobjectdtc.
 
I was experimenting with the pageobject but I'm definitely out of my expertise with this particualr item.
 
Hi Jeff,

I've never used it but i think it goes like this

Code:
thisPage.navigate.Testsub( ssql)

hope that helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top