Problems with Confirm Function - User Error, JavaScript Error or Server Error?

My client has a php based bulletin board application on an internal server. It is set up so that users can post to the board and delete the post at their leisure. There is a delete page that the user visits that calls a Confirm() JavaScript function to give the user a chance to stop from accidentally deleting the post. If the user confirms the action, the post is deleted. If they cancel, they are taken to the “Edit Post” page.

Just recently, the function stopped working for the client. He gets a script error in Firefox:
Message: Object expected
Line: 210
Char: 1
Code: 0

I cannot seem to replicate this issue at all. The application runs just like it is supposed to on my test server (Xampp) under IE 7, 8 and 9, Chrome and Firefox. It also runs fine on my public server under the same browsers. No errors are returned and the function does what it is supposed to do.

The real head scratcher is that I uploaded a copy to a web server with a public address to have the client try. The client did not run into the JavaScript error (using the same browser and computer as before). Everything worked just like it was designed.

In case of a corrupt file, I had the client overwrite the existing application with a fresh copy (PHP and JavaScript) on the internal server with the same files that worked for him on the public server. No luck.

The client’s IT department claims that no changes have been made to the server. Other JavaScript components (JQuery UI tabs and form validation) work just fine.

Since the web server is internal and the company is concerned about security, the web server is not connected to the internet. I don’t think that this function is using JQuery. Regardless, the JQuery library (jquery-1.4.2.min.js) is stored locally instead of referencing the JQuery server so there shouldn’t be an issue with some kind of deprecated command that I was using… if it worked before, it should work now.

I am stumped. I have tried everything that I can think of to isolate the problem. Does anyone have any idea why this would be happening?

Here is my JavaScript function:

function showConfirm(target, current) {
	var r=confirm("Are you sure you want to delete this item?  This action cannot be undone!");
	if (r == true) {
	else {

One thing you can try is using window.location.replace

SgtLegend: Thanks for the response. I will give that a shot.

In general, another thing that I thought of is that the function is being invoked by the OnClick action on the link in the HTML. Could that be causing the problem? Is there an issue with that action not being well supported?

There should be no issue there at all.

Is line 210 one of the location lines?
Can you put together a test page so that many more people here can try your code out in their own browser?

The link needs to have a “return false” at the end of the onclick code to stop the link’s default href action

<a href="#" onclick="confirmDelete(params); return false">Delete this post</a>

Do you think that would fix this error that the OP is experiencing?

Message: Object expected
Line: 210

I put together a test version that everyone can access. It doesn’t have full functionality like uploading pictures and the confirmation email but it still works. None of those features are associated with the JavaScript functionality.

It is located at:

Since the notification email doesn’t work, you can delete your post on the Administration page:

The Administration page is where my client was having trouble with the JavaScript.

pmw57 and dantel: You’re saying that I have to have a “return false” after the onClick? Line 210 is one of the links with the onClick lines.

If I used the confirmDelete function, it would have to be something like this, right?

function confirmDelete(deleteURL) {
if(confirm("Are you sure?") {
window.location.replace = deleteURL;

I would use the onClick formatting that you suggested above:

<a href=“#” onclick=“confirmDelete(params); return false”>Delete this post</a

Is this method more widely supported by browsers than my original one?

I’m willing to give this a shot. Thanks for the suggestions.

I’m using IE with “display a notification about every script error” enabled. IE reports a scripting error in the menu code:

Line: 329 Error: Invalid argument.

document.body.appendChild(dropul) //move main ULs to end of document

That’s because the dropul doesn’t contain a valid element. You can solve that by enclosing that line and the rest of the code in the loop, in a condition that checks if dropul contains a valid element.

if (dropul.nodeType === 1) {

Firefox reports the same problem, when you open up its Error Console (in Tools menu)