Passing variables into javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Passing variables into javascript

Post by GeXus »

Would something like this work?

file.js?name=tada

How would I get this variable inside the js file?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I normally set Javascript global level variables either before the script is included or set them before calling the functions that are dependent on them. Similar to this:

Code: Select all

<script type="text/javascript">
  var foo = 'bar';
</script>
<script type="text/javascript" src="file.js"></script>
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:I normally set Javascript global level variables either before the script is included or set them before calling the functions that are dependent on them. Similar to this:

Code: Select all

<script type="text/javascript">
  var foo = 'bar';
</script>
<script type="text/javascript" src="file.js"></script>
Jesus man...it's impossible to beat you to the punch...I swear to god your cheating...

You using some form of auto-redial/responder script which returns canned answers to questions... :P

Cheers :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'm telling you, there is something unnatural with the speed, accuracy and correctness in his answers. It is a sight to behold.
Post Reply