#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    Uncaught ReferenceError: set_cookie is not defined


    i get this error in this code when i look in the console on Google chrome:

    Uncaught ReferenceError: set_cookie is not defined

    this is the code:



    <script src="js/lightbox.js"></script>
    <link href="css/lightbox.css" rel="stylesheet" />
    <script type="text/javascript">
    function set_cookie(){
    document.getElementById("cookie").innerHTML="<?php cookie_set() ?>";
    }
    $("#overlay").hide();
    </script>

    <?php
    function cookie_set()
    {
    setcookie("allow_cookies","true",time() + (20 * 365 * 24 * 60 * 60));
    }
    ?>
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    That code doesn't tell us anything. Where is that set_cookie() called? The console gives you the specific line of the error.
    Last edited by Jacques1; December 9th, 2012 at 09:44 AM. Reason: nonsense
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,502
    Rep Power
    594
    Your code doesn't make any sense. You are substituting a return value from cookie_set into your JavaScript definition but cookie_set does not return anything. That is not a normal PHP error message. There is no line number in the message.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0
    set_cookie() is called by this:

    <input name="ok_hide" type="button" onClick="set_cookie()" value="Ok, i get it.">

    i want it to set a cookie, hide the button but i dont want it to redirect.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,502
    Rep Power
    594
    That makes even less sense. A JavaScript call will not redirect unless you program it to. PHP will never see that call anyway. You need to understand that JavaScript is client side and PHP is server side. Look at the source in your browser, is that what you expect for your JavaScript function definition?
    Last edited by gw1500se; December 9th, 2012 at 09:58 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo