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

delete button

Status
Not open for further replies.

JennyLu

Programmer
May 31, 2001
7
0
0
US
I have a table generated from our database on the customer page. On that page I want to create a DELETE button. After user click DELETE button, the row which user just selected will be deleted from the table. How can I capture which row the user selected? Thanks!
 
you must write key information about that row to the method that will be called when they click the button, so for example:

<input type=button value=Delete onClick=&quot;javascript:deleteRecord(1);&quot;>

where deleteRecord would be a client side function on your page that would post that information to the server side function that could do something with it. For example:

<script language=javascript>
function deleteRecord(recordNum){
var url = &quot;delete.asp?record='+recordNum;
location=url;
}
</script>

then you can pick up the value on delete.asp, and delete the record.

hope that helps. :)
paul
penny1.gif
penny1.gif
 
Thank for your response. But I don't know how to dynamically pass the parameter value(recordNum) into that function deleteRecord() based on user selection.
 
Well, when you're writing your table rows out to the screen, you're iterating through a recordset, yes?

So for any given row, you have a primary key associated with that row, right?

so, you just write out the button action just like you would any other information on that row.

So for instance, if your primary key field was called 'pk', and your recordset was called 'rs', then you might write the button like this:

response.write(&quot;<input type=button value=Delete onClick=&quot;&quot;javascript:deleteRecord(&quot; & rs(&quot;pk&quot;) & &quot;);&quot;&quot;>&quot;)

so that for each row, you just write the buttons out when the page is rendered, so that each button (row) gets its respective pk.

paul
penny1.gif
penny1.gif
 
I was requested to have only one DELETE button below the table on that page. The user does not want to put delete button on every single row. Thanks again for your kind help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top