473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to execute an SQL in onClick of an HRef ?

33
Hi,

I have a page showing the result of a search criteria. I'm using VB script. I have given link to an attached file for each record. There is also a field "Number of downloads" in my table. When a user clicks on a particular link, I want to update (increment by 1) the No. of downloads field in my table, for that particular record. My code is as follows.
<TD nowrap borderColor=#800000 width="220"> <A id=D href= "http://localhost/MyPage/<%= trim(replace(rs(7),"#","")) %>" title="Click here to view full article"
onclick=<% sqlQuery = "Update Book set NoOfDownloads = NoOfDownloads+1 where SlNo = " & rs(9)
cn1.Execute sqlQuery %> >

where rs(7) is the attached file name and rs(9) is the SlNo(PK).
But this update query is executed every time the page is loaded, evenif not clicked. Also it is updating for all the records having attachments.

Plz help me.

Matsam
Jul 20 '07 #1
4 6813
jhardman
3,406 Expert 2GB
Matsam,

ASP only runs when the page is being loaded. That is the only time it runs. Period. The code executes wherever it is written, regardless of being in an onClick event or whatever and considers everything outside of the asp code tags to just be static HTML it needs to print to the page. Therefore, putting an asp code inside an onClick event is completely meaningless. The script will execute the command while loading.

If you want to run an asp script on an onClick event try using a pop-up window or an iframe which you can reload while the rest of the page stays the same. Put the script you need to run in the pop-up window and when it is done you can have the pop-up window interact with the parent window thru javascript (window.opener I believe) if you need to pass values back, then close the pop-up window if you like.

Does this answer your question?

Jared
Jul 20 '07 #2
Matsam
33
Matsam,

ASP only runs when the page is being loaded. That is the only time it runs. Period. The code executes wherever it is written, regardless of being in an onClick event or whatever and considers everything outside of the asp code tags to just be static HTML it needs to print to the page. Therefore, putting an asp code inside an onClick event is completely meaningless. The script will execute the command while loading.

If you want to run an asp script on an onClick event try using a pop-up window or an iframe which you can reload while the rest of the page stays the same. Put the script you need to run in the pop-up window and when it is done you can have the pop-up window interact with the parent window thru javascript (window.opener I believe) if you need to pass values back, then close the pop-up window if you like.

Does this answer your question?

Jared

Hi

Thanks for ur reply.. But sorry... my problem is not solved. Also I am not familiar with popups & iFrames... Any simple method for the same ??
Or else plz give me the code for displaying popups while clicking a hyperlink.

Thnks

Matsam
Jul 21 '07 #3
jhardman
3,406 Expert 2GB
It all depends on what you need to do. Is sending a small bit of data to the dbreally the only thing you need to do? If that is all, then make a script that does this, but put it on a new page. When the user does the important action, say clicking a button or whatever, then open that page. If this action is an existing HTML control, like a form element you will probably need some simple javascript to open the pop up. I am not a javascript expert, but the code is something like:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" onClick="window.open('mydataTrackerPage.asp')">
Notice, I would put the script for changing the db on the myDataTrackerPage.asp, when that page is loaded it will execute the db update. You can close the popup after it has served its purpose with javascript as well, the code is something like this:
Expand|Select|Wrap|Line Numbers
  1. <... onLoad="this.window.close()">
iframes are more complicated and weren't well-supported when I learned HTML, so I never bothered, but I am aware that they can do the same thing, perhaps better, although this is a matter of opinion.

Jared
Jul 23 '07 #4
Matsam
33
It all depends on what you need to do. Is sending a small bit of data to the dbreally the only thing you need to do? If that is all, then make a script that does this, but put it on a new page. When the user does the important action, say clicking a button or whatever, then open that page. If this action is an existing HTML control, like a form element you will probably need some simple javascript to open the pop up. I am not a javascript expert, but the code is something like:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" onClick="window.open('mydataTrackerPage.asp')">
Notice, I would put the script for changing the db on the myDataTrackerPage.asp, when that page is loaded it will execute the db update. You can close the popup after it has served its purpose with javascript as well, the code is something like this:
Expand|Select|Wrap|Line Numbers
  1. <... onLoad="this.window.close()">
iframes are more complicated and weren't well-supported when I learned HTML, so I never bothered, but I am aware that they can do the same thing, perhaps better, although this is a matter of opinion.

Jared

Hi

Thanks a lot... As suggested by u, I placed a new page for download in between and managed to solve my problem.
Thanks again

Matsam
Jul 24 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: GhislainTanguay | last post by:
Hi everyone. I'm not from Internet word i have some difficulties with events. I have a session variable who change the selected language (French or English) and i try to change this variable...
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
3
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement...
2
by: Dave | last post by:
Hi, I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static message of "Please Wait..." since the query takes...
4
by: Ian Kelly | last post by:
Hi All, I have an .net form that is split into two frames. The left frame has a tree that displays a list of all the customers. The right frame displays the appropriate clients information. ...
11
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
3
by: Spartanicus | last post by:
I need to execute a function after a link to a section within the same document has been clicked and the navigation has occurred. When using the onclick event handler the JS function is executed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.