views:

50

answers:

1

Hello, heres basically what I need to get done.

I have a jsp page which allows me to add/modify/delete an item.

The items are stored in a database which I have controller classes to access(dont worry bout that part)

When an item gets selected and deleted the id of the item gets sent to the controller to be processed.

The item will not always be deleted if their is a foreign key constraint so I send either a delete=true or delete=false through url back to the jsp page.

I would like to have it so a javascript function gets called displaying an alert saying the item was deleted or the item was not deleted.

can someone please tell me the best way to do this? thank you

A: 

You could place a function on the page that loads when the page loads (maybe attaching to the body onload event). It could look something like this if you placed the function on the page, just before the closing body tag, although it would be recommended that you define the function in a separate js file:

<script type="text/javascript">
function ShowDeleteMessage()
{
  var regex = /delete=(true|false)/;
  var messageDeleted = regex.exec(location.href)[1];
  if(messageDeleted == "true"){
    alert("Deleted successfully");
  }else if(messageDeleted == "false") {
    alert("Was not deleted");
  }
}
ShowDeleteMessage();
</script>
</body>

Hope that gets you in the right direction.

Carl
Ahh I forgot you could do that, still learning javascript. Thanks a lot