JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old October 2nd, 2006, 11:15 AM
headpoop headpoop is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 9 headpoop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 10 sec
Reputation Power: 0
Display variable within an external .js file

I just started working with javascript a few weeks ago. If i create an external javascript file with the following

var maintext="This text needs to be displayed"

and save it as "external.js" What code do i need to put in an html document to display this variable? is the syntax for the javascript file correct?

Reply With Quote
  #2  
Old October 2nd, 2006, 12:09 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 541 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 15 m 6 sec
Reputation Power: 3
js vars

If you reference the external file in the page's head section, the variable will be available to subsequent javascript.
To test it, you could use another in-page script that "alerts" it. A simple way would be to "document.write" it wherever you want it to appear. But the correct way to do this would be to have some in-head script modify the DOM
Comments on this post
MadCowDzz agrees: I like the DOM way.

Reply With Quote
  #3  
Old October 4th, 2006, 11:07 AM
headpoop headpoop is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 9 headpoop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by Mittineague
If you reference the external file in the page's head section, the variable will be available to subsequent javascript.
To test it, you could use another in-page script that "alerts" it. A simple way would be to "document.write" it wherever you want it to appear. But the correct way to do this would be to have some in-head script modify the DOM


Thanks man, that was just what I was lookin for.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Display variable within an external .js file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway