PDA

View Full Version : Html variable insert?



HomeStar
04-28-2005, 10:02 PM
This should be easy for someone that knows what there doing.

want to create a file called

country.js
<body>
<script language="javascript">
<!--
var albania = 4;
//-->
</script>
</body>

and then pass the "4" to many different html pages

<script language="javascript">document.write(albania);</script>

but it's not working. :(

jscheuer1
04-29-2005, 01:10 AM
You might show us what you've tried. For something simple like that, the sending page can have this on it:


<a href="nextpage.htm?var1=albania">Click here to go Albanian Style!</a>

Then on the recieving page have:


<script type="text/javascript">
var text = unescape(window.location.href);
function delineate(str) {
theleft = str.indexOf("=") + 1;
theright = str.indexOf("&");
return(str.substring(theleft, str.length));
}
var sentInfo=delineate(text)

document.write(sentInfo);

</script>

mwinter
04-30-2005, 05:56 PM
[...] want to create a file called country.js
<body>
<script language="javascript">
<!--
var albania = 4;
//-->
</script>
</body>Perhaps I'm reading too much into the above, but a script should never contain bare markup. The content of country.js should just be


var albania = 4;included in the head element with


<script type="text/javascript" src="country.js"></script>


and then pass the "4" to many different html pagesIf you're looking to include the same content in several different documents, you might want to look into server-side include (SSI) support.




function delineate(str) {
theleft = str.indexOf("=") + 1;
theright = str.indexOf("&");
return(str.substring(theleft, str.length));
}I really do wish you'd stop posting that particular function. Please appreciate how badly written, and inflexible, it is. It may be fine in situations where only one name/value pair exists in the query string, but that is hardly a robust, future-proof solution.

Mike