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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Need script to fire a function

    Hi
    I need this script to fire a "function msg()" instead of displaying the "document.write(enabled)" statement. Any idea's?? Thanks Joe

    Code:
     
    var cookieEnabled=(navigator.cookieEnabled)? true : false 
    if (cookieEnabled){
    document.write("enabled"); 
    }else{ 
    document.write("disabled"); 
    }
    Last edited by Papajo; 06-20-2009 at 06:50 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    var cookieEnabled=(navigator.cookieEnabled)? true : false 
    if (cookieEnabled){
    msg();
    }
    But why not simply combine the function msg() with this?

    Code:
    var cookieEnabled=(navigator.cookieEnabled)? true : false 
    if (cookieEnabled){
    // show the message
    }

    "There are a lot of tired legs in those white shirts" - Football commentator

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Sorry but the script still won't fire with replacing the document.write with msg();
    I tried that already, thought it would work also??


    var cookieEnabled=(navigator.cookieEnabled)? true : false
    if (cookieEnabled){
    msg();
    }

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Well, there must be some other problem. You can see that this works:-

    Code:
    <script type = "text/javascript">
    
    var cookieEnabled= true;
    if (cookieEnabled){
    msg();
    }
    
    function msg() {
    alert ("My message");
    }
    
    </script>

  • Users who have thanked Philip M for this post:

    Papajo (06-20-2009)

  • #5
    New Coder
    Join Date
    Oct 2008
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ok I found the problem, I had the javascript before the form tag, I placed it after and the script worked, go figure!!!!
    Thanks for your help. Joe


  •  

    Posting Permissions

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