473,788 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

loading a string from an external file

Hi,
i was wondering if it is possible to load text into a string from an
external text file. the reason is that i have a very large string and
it is making my script very messy.

also, is it possible to have some dynamic parts of the text from the
text file? for example, if i load in a string and there is a part of
it that inserts a value from a variable like the following:

'The number of people is ' + var_people_num;

....so the text from the external file would load but these parts would
be given the value of a variable contained in the script that calls
the external file. its not absolutely crucial that i obtain this but
it would help me seperate large chunks that complicate the script. any
ideas would be great. cheers

burnsy
Jul 23 '05 #1
1 3242
mr_burns wrote:
Hi,
i was wondering if it is possible to load text into a string from an
external text file. the reason is that i have a very large string and
it is making my script very messy.

also, is it possible to have some dynamic parts of the text from the
text file? for example, if i load in a string and there is a part of
it that inserts a value from a variable like the following:

'The number of people is ' + var_people_num;

...so the text from the external file would load but these parts would
be given the value of a variable contained in the script that calls
the external file. its not absolutely crucial that i obtain this but
it would help me seperate large chunks that complicate the script. any
ideas would be great. cheers

burnsy


Sure... this is easy.

In the main page, add the following:
<SCRIPT type="text/javascript" src=include.js> </SCRIPT>

Then, in the included file, named include.js, you can do the following:

////////////////////////////
var long_string = "This is a Test of a Long String with a %VARIABLE1%.";
/////////////////////////////

Then, later on in the main page, you can do something like this:

<SCRIPT type="text/javascript">

var var1 = "variable that can be replaced";
myData = long_string.rep lace( /%VARIABLE1%/, var1);
alert(myData);

</SCIPT>

Does this do what you need?

Brian

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5211
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have to wait for the external resource to load to show up the page, thus giving a perceiving faster load time for the user.
5
3992
by: bissatch | last post by:
Hi, I have just managed to install DOMXML on my apache/PHP setup. I am running PHP 4.3.0 and Apache2. $xmldoc = domxml_open_file("inc/menu.xml", DOMXML_LOAD_DONT_KEEP_BLANKS); When I try to load an XML file using the above, it gives me the following error:
4
3286
by: blackhawk | last post by:
I need to build a web page that has to potentially display a large amount of data in two grids on the same page. The HTML file with all of the formatting is about 7MB in size. This is too large and I need to implement some kind of "client side" lazy loading. What I mean is this: I want to display a grid that only shows, say, 20 records. I need an external scrollbar control that I can then show on the screen next to the grid. When...
17
2786
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script language="javascript" src="../scripts/base.js" type="text/javascript" /> } </script> Obviously this would cause n error but this would give you an idea of what I'm looking to do. I know I can do this with a simple include but...
1
3811
by: ozzy.osborn | last post by:
Hello All, I have been struggling with a cross browser solution to loading external javascript files on the fly. I have been successful using the following code in IE6: var newScr = document.createElement("SCRIPT"); newScr.src = "newScr.js"; newScr.type="text/javascript";
6
2776
by: Venkatesh | last post by:
Hello All, I have couple of doubts regarding the concept of on-demand javascript loading using javascript code. I could see on the net different techniques for achieving this - techniques like: 1. document.write("<script src= language='JavaScript'></script>); 2. sc = document.createElement("<script>"); sc.setAttribute("src", ); and append this to the head
4
2387
by: teddarr | last post by:
Here's my quandry.....I am building a phone book program with student and staff classes. In main() I am to define 2 arrays 1 for students and 1 for staff. Each array will hold objects. I have declared the student array and I have a constructor in the student class that doesn't take any arguments. So I have no problem declaring the objects. The problem is, how do I define the objects and load them in the array? Each student object...
20
4047
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great and populates into the webpage; however, executing javascript has a few problems: 1. Opens on a blank page, but not a new page. It appears to compeltely overwrite the original page. I want it to update the existing page by loading within a <div>...
0
3902
by: whochrisporter | last post by:
Hi, thanks for reading and helping me first of all. Now to the question.. I need to load external images into a scrolling slideshow (its like a sliding rotating banner) flash file using an external text file. I think I may have the concept down, I'm just not good in coming up with my own script. I was thinking to use the loader component because for the sliding to work, I have to set the images (5 of them) next to each other so every few...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.