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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button's OnClick event runs without clicking

Status
Not open for further replies.

wingpeople

Programmer
Oct 18, 2002
24
US
I'm running a SELECT that returns several records in a recordset. I want to display all the records retrieved, with a "CHANGE" and a "DELETE" button below each record.

I use a WHILE...NOT EOF loop to iterate through the recordset.

I've got it displaying the records OK, I've got the buttons displaying OK, and I've got the CHANGE button working OK (it does a redirect). However, I'm having problems with the DELETE button.

I define the button within the WHILE...NOT EOF loop this way:

<button type=&quot;button&quot; onClick=&quot;<%DeleteTheRecord(ID)%>&quot;>Delete</button>


I have a vbScript function called DeleteThisRecord which gets passed the ID and runs a DELETE query to delete the record.

The problem is that DeleteThisRecord is getting called as I iterate through the recordset, so all the records get deleted (one at a time) before the user ever gets to see the data OR either of the Buttons. Shouldn't this function only be invoked AFTER the user clicks a DELETE button associated with one of the records in the recordset?
 
The problem is two-fold. 1) You have defined this function on the server, which cannot be called by a client-side event. Once the ASP finishes generating and sending the page it is done. 2) If you wanted this to be a client-side call you would have to format it like so:
Code:
<button type=&quot;button&quot; onClick=&quot;DeleteTheRecord(<%=ID%>)&quot;>Delete</button>

You will not be able to make changes to the database from the client's page, this will require (at the simplest) a query to a new page, ie a form submission.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top