Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry confirm() function not working!

    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>
    Code:
    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
    Code:
    <input type="submit" onClick="return confirmUpdate()" name="update" value="Update Selected" />

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <header>?
    Code:
    <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" />
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.')"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    It's better if you post your code.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    New Coder
    Join Date
    Apr 2004
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •