Results 1 to 3 of 3

Thread: js in <body>

Hybrid View

  1. #1
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    184

    js in <body>

    is it necessary that js are placed in the header?, im running into a frustrating issue with my script placed in the body as i need to create a js var and give it a value using php
    this is the souce code on my browser and it clearly shows a value for thid
    PHP Code:
    <script type="text/javascript">
            $(
    '#suggest').click(function(){
                
    window.location.href='TimeSheet.php?batId=474&empId=33&admin=false&suggest=true';
                                });
            $(
    '#cancel').click(function(){
                
    javascripthistory.go(-1);
                
                                });
            $(
    '#logout').click(function(){
                
    window.location.href='logout.php';
                                });
                var 
    thid=224// here
        
    </script> 

    and this is the js console exception
    PHP Code:
    <script type="text/javascript">
            $(
    '#suggest').click(function(){
                
    window.location.href='TimeSheet.php?batId=474&empId=33&admin=false&suggest=true';
                                });
            $(
    '#cancel').click(function(){
                
    javascripthistory.go(-1);
                
                                });
            $(
    '#logout').click(function(){
                
    window.location.href='logout.php';
                                });
                var 
    thid=;                                         //here    exception thrown
    [error]Uncaught SyntaxErrorUnexpected token ;[error]
        
    </script> 
    this occurs sometimes only a havent been able to understand why !!
    Last edited by wiss.dev; Mar 20th, 2012 at 07:19 PM.

  2. #2
    Web developer Nightwalker83's Avatar
    Join Date
    Dec 01
    Location
    Adelaide, Australia
    Posts
    9,832

    Re: js in <body>

    If you are passing a value from php to javascript this might help. Although, you might want to consider using ajax instead.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    DON'T BUMP YOUR POSTS!!! Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  3. #3
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    184

    Re: js in <body>

    Thanks NightWalker..
    that's exactly how i'm doing it, but the issue is on the client side. if you check my source page code it clearly has a value of 224 while in the js console the value is missing and an exception is returned

Posting Permissions

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