...

View Full Version : confirm() function not working!



o0katz0o
04-28-2004, 06:49 AM
I really don't get it. How can this simple little function NOT be working.
I've looked at it a ton of times, but the confirm box just doesn't come up

this is the function i have in <HEADER>


function confirmUpdate() {
var agree = confirm("You are about to update the currently selected template.\nPlease check it is the one you want to update and click OK to continue.");
if (agree)
return true;
else
return false;
}


and this is what is calling it in the <BODY> tag


<input type="submit" onClick="return confirmUpdate()" name="update" value="Update Selected" />

glenngv
04-28-2004, 07:25 AM
<header>? :confused:


<head>
<script type="text/javascript">
function confirmUpdate() {
var agree = confirm("You are about to update the currently selected template.\nPlease check it is the one you want to update and click OK to continue.");
if (agree)
return true;
else
return false;
}
</script>
</head>

You can also simply do it like this:

<input type="submit" onclick="return confirm('You are about to update the currently selected template.\nPlease check it is the one you want to update and click OK to continue.')" name="update" value="Update Selected" />

o0katz0o
04-28-2004, 10:28 AM
yeah I meant <HEAD>
it is placed between <HEAD></HEAD> file
OK, I tried your suggested method and it works BUT I'm getting a Javascript error in my brower around that line. So there is obviously something wrong with the code, that isn't visible yet.
maybe something else is making it not work properly?

Oh yeah, the javascript error is:
Unterminated string constant

glenngv
04-28-2004, 10:42 AM
Did you put it on one line or you missed the closing single quote?

onclick="return confirm('You are about to update the currently selected template.\nPlease check it is the one you want to update and click OK to continue.')"

o0katz0o
04-28-2004, 02:37 PM
yes, it's on one line with single quotes used
I actually tried adding language="javascript" to <SCRIPT> and that got rid of the javascript error, but the function way still doesn't work.
why doesn't the function way work?

Willy Duitt
04-28-2004, 03:15 PM
Did you try cutting and pasting Glenns code example because it works fine for me.

Or did you just attempt to edit your current codes? If so, as Glenn pointed out, your editted code is broke across several lines or you missed the closing quote or or you did not use single quotes to delimit the confirm string.

.....Willy

glenngv
04-29-2004, 03:45 AM
It's better if you post your code.

o0katz0o
04-30-2004, 03:02 AM
ok, I FINALLY figured it out.
I actually had my javascript within PHP code like this

$header = <<<HEADER
<script>
function confirmUpdate() {
var agree = confirm("You are about to update the currently selected template.\nPlease check it is the one you want to update and click OK to continue.");
if (agree)
return true;
else
return false;
}
</script>
HEADER;

and what was happening was PHP was intrepreting the \n as a new line, which is what screwed it up. all I had to do was use \\n and that worked. :-)
Mystery solved!
thanks everyone! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum