homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript Question
Confirmation alert box not working properly
kevinj




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

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.

 

txbakers




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

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;

}

kevinj




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

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?

txbakers




msg:1494769
 8:23 pm on Jan 17, 2003 (gmt 0)

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.

kevinj




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

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.

txbakers




msg:1494771
 9:48 pm on Jan 17, 2003 (gmt 0)

I'll write out something and test it.

DrDoc




msg:1494772
 4:44 pm on Jan 18, 2003 (gmt 0)

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;
}
}

txbakers




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

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.

kevinj




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved