Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: open

JavaScript Question

Confirmation alert box not working properly

   
6:31 pm on Jan 17, 2003 (gmt 0)

10+ Year Member



I've set up a page for my client to edit or delete records from a database. If they click on the delete button, I've set it up so they get an alert box asking for them to confirm that they want to delete the record to avoid a mistaken delete. The alert box comes up fine when I click on the delete button, but when I confirm the delete, I get a Javascript error in IE 6 Win.

Runtime Error
undefined is null or not an object.

My code that calls the javascript alert box is:

<form action="/exhibitorhousing/housing-delete.asp" method="post" onSubmit="Delete(this. form); return false"><input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>"><input type=hidden name="MODE" value="DELETE"><input type=submit value="Delete"></form>

The Javascript is:

function Delete(thisform) {
if (confirm("Are you sure you want to delete this reservation?"))
thisform.submit();
}

Any thoughts on how I can eliminate this problem?

Thanks.

7:44 pm on Jan 17, 2003 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes. You can't call the onSubmit event and then submit the form within the function of the onSubmit....... etc.

Here is the code:

<form action="/exhibitorhousing/housing-delete.asp" method="post" onSubmit="return Delete(this. form)"><input type=hidden name="HOUSING_REQUEST_ID" value="<%= HOUSING_REQUEST_ID %>"><input type=hidden name="MODE" value="DELETE"><input type=submit value="Delete"></form>

the script:

function Delete(thisform) {
if (confirm("Are you sure you want to delete this reservation?"))
return true;
}else{
return false;

}

8:04 pm on Jan 17, 2003 (gmt 0)

10+ Year Member



Thanks txbakers. I edited the code the way you recommended. It deleted the record fine, but it didn't give me the confirmation alert box, just went right ahead and deleted the record. Any thoughts?
8:23 pm on Jan 17, 2003 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



onSubmit="return Delete(this. form)"

You don't need "this.form" in the onSubmit. You can just use "this" which should work.

Give it another try and let me know what happens.

8:49 pm on Jan 17, 2003 (gmt 0)

10+ Year Member



I made the change and it doesn't give me the confirmation alert box. Just deletes the record and gives me two Debugging error prompts. The first is object expected and the second is syntax error.
9:48 pm on Jan 17, 2003 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I'll write out something and test it.
4:44 pm on Jan 18, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The JavaScript function should read like this:

function Delete(thisform) {
if (confirm("Are you sure you want to delete this reservation?")) {
return true;
}else{
return false;
}
}

6:06 pm on Jan 18, 2003 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes, thanks for catching that typo.

It will work with that extra brace at the bottom to close the function.

Because there was a syntax error in the function (no curly brace at the bottom) the javascript was ignored and your form was processed without it.

If you want to test your page code without updating anything, just comment out the cmd.execute lines in your ASP code.

2:17 pm on Jan 19, 2003 (gmt 0)

10+ Year Member



Thanks DrDoc and txbakers! It works perfectly now. No IE debug JS errors, the alert box asks for a confirmation before the delete, and upon confirmation the record is deleted. I really appreciate your help!
Kevin
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month