You don't need to put the variable in a function...just have it in the script tags and it will be global. Also you don't want it to be the php file itself...the script needs to be written by the php file and a number needs to be assigned to it. Just make sure that javascript gets hit before you run the part of the javascript that is looking for it.