PDA

View Full Version : Repetitive Text Script


sss1
08-19-2003, 09:27 AM
Hello,

i've had a trawl through the rest of the site to no avail so have come here for help!

I look after a site where various bits of statistical information change on a regular basis and we have to manually go through and change about 30-40 figures, of which 6 are repeated about 6-7 times throughout the site.

Is there a script available which will act as a basic content management sort of script, that will allow me to change these particular figures on one page, which will change everything throughout the rest of the site?

Hope this is clear and thanks for your help

S

Kor
08-19-2003, 11:38 AM
Yes, you can do that using javascript

1. build a .JS file including your variables to be change:

var variable01 = 60;
var variable02 = 50;
var string01 = "whicheverstringno1";
var string02 = "whicheverstringno2";

...

let's say your .JS file will be script.js, and will be in the same root with the rest of the files

2. in the body of the html documents, replace those values with a small script

for instance:
<script language="JavaScript">document.write(variable01);</script>

3. in the head of the html document put the script ref like:

<script language="JavaScript" src="script.js"></script>


Now, to change the variables you will have only to open the script.js file (even with an simple ASCII editor, as Notepad, and modify the values one time...

sss1
08-19-2003, 02:58 PM
for small numbers this is fine, however for larger numbers, that require commas to separate the digits, it's not working for me.

Is there another version which can show text/numbers with commas?

thanks again

S

glenngv
08-20-2003, 04:00 AM
then use arrays

var arrNumbers = new Array(60,50,40,30);
var arrText = new Array("text1","text2","text3");


then in the html pages:

<script language="JavaScript">document.write(arrNumbers[0]);</script>
...
<script language="JavaScript">document.write(arrNumbers[1]);</script>
...
<script language="JavaScript">document.write(arrText[0]);
</script>

Kor
08-20-2003, 08:22 AM
If text, commas will be shown with no problem, as they are strings. When are shown berween "..." any character is treated as string (except some reserved javascript special characters like " ; ' / In that case we may use the backslash to "confirm" that there is a simple string. Ex: \" or \;

If number, well, you may build a small script to insert commas or whichever when document.write it

sss1
08-20-2003, 10:57 AM
thank you for your help.

I'm sure this is a v. straightforward thing and so will endeavour to read around the subject more.

Thanks :)

Si