Hi Guys! I want to send variables into a javascript file How would I go about this? All I need is the code to send the var into the file. E.g. <script type="text/javascript" src="http://www.example.com/file.js?id=whatever"></script> HTML: Thanks for your help!
Hi Chris. You can try the following code: <script type="text/javascript">id=whatever;</script> <script type="text/javascript" src="http://www.example.com/file.js"></script> Code (markup): Then you should be able to use the id value in file.js code.
Thanks for the reply, is this how I print the variable inside the .js file? document.write(" +delineate2(id)); HTML: or is that wrong?
If you define the variable in an earlier script tag, when you include your other file below it, it'll have access to the previous variable, so yes, it should have no trouble document.writing it. I also know that it is possible to pass variables through the include, I've seen it done before. You can try doing your example where you put "?id=whatever" at the end because it's likely that just might work.
Chris, 1. "file.js?id=whatever" shouldn't work as desired with the id value unless file.js is parsed by the server. 2. Did you check the document.write code with id variable defined in an earlier script tag? Does it work fine for you?