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

delete from database

Status
Not open for further replies.

miroiti

Programmer
Jun 20, 2009
18
EG
iam a beginner in javascript and need some help,
i want when user press delete button delete it from interface also delete from databse
i successed to remove from interface but i canot remove it from data base becouse it is server side and javascript is client side,.. plus i have to detect which row the user want to delete from table .....how can i do this???

here is the code

<TD><input type="button" name ="Delete" value ="Delete" onclick=del()> </TD>

function del()
{
var current = window.event.srcElement;
//here we will delete the line
while ( (current = current.parentElement) && current.tagName !="TR");
current.parentElement.removeChild(current);
}

 
Hi

JavaScript can not delete from your database. And be grateful for that.

Change your [tt]input[/tt]'s [tt]type[/tt] from [tt]button[/tt] to [tt]submit[/tt], and modify your [tt]form[/tt] so the server-side script will receive the record identifier.

Or use AJAX to send a request to the server-side script.

Anyway, we know nothing about your [tt]form[/tt], so we can not suggest any modification.

Feherke.
 
I would suggest using AJAX - since your work flow indicates you don't actually want the page to reload when you click the delete button.

AJAX is a mechanism to send some data to the server without reloading the page. It effectively does this by sending the data as a form POST or GET request. You can also get the response back from the server and choose to do something with it (but this is not a requirement).

You need to be aware that you can only use AJAX to talk to the server on the same domain as you are viewing the page on. If you need to do an AJAX post to a different domain, you will need to implement a Proxy server on your server (that will forward on the request to the proper destination whilst "tricking" the browser into thinking it is submitting it to the current domain).

Check out the AJAX forum here for specific problems in this realm. There are some very good examples online as well.

With the increased use of Javascript frameworks (Prototype, jQuery, Ext, Mootools, Dojo *the list is huge*) AJAX is easier to do. Check it out... it's a good solution to your problem.

Cheers!
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top