Variable & Value

Intro
Passing Data
Name & Value
Muliple Elements
Variable & Value
 
Data to Popup
Data from Popup
Opener
Arrays
Form Method
 

In the following example variables are assigned a string value in the form of a line of text.
Before sending this data to another page a delimiter is added to mark the end of a value.
All the values are then constructed into a new single value that is transfered to the other page.

When this value is recieved the new single value is deconstructed and the delimiters removed.
The original variables are then recreated with their values.

To check a variables value select any of the following 4 links.

myVar0 myVar1 myVar2 myVar3

You may add your own string here

Transfer Data

In the sending page

<script type="text/javascript">
<!--
myVar0="One fine day in the middle of the night"
myVar1="Two dead men got up for a fight"
myVar2="Back to back they faced each other"
myVar3="Drew their swords and shot each other"

delimiter="&"

fullString=""
function passData() {
for(i=1;i<4;i++){ // number of variables
fullString+=window['myVar'+i]+delimiter
}

location.href = 'page2.htm' + '?' + escape(fullString)
}
//-->
</script> 

<a href="#null" onclick="passData();return false">Transfer Data</a>

In the recieving page (page2.htm)

<script type="text/javascript">
<!--

function getData(){

if (location.search.length > 0){
dataPassed = unescape(location.search.substring(1))

document.getElementById("display1").innerHTML="String including delimiters passed to this page :<br>"+dataPassed

var temp_save = dataPassed.split("&")
for(i=0;i<temp_save.length;i++){
window['myVar'+i]=temp_save[i]
}
document.getElementById("display2").innerHTML=myVar0
document.getElementById("display3").innerHTML=myVar1
document.getElementById("display4").innerHTML=myVar2
document.getElementById("display5").innerHTML=myVar3
}

}

// add onload="getData()" to the opening BODY tag

// -->
</script>

<div id="display1"></div>
<P>Reconstructed string:
<span id="display2"></span><BR>
<span id="display3"></span><BR>
<span id="display4"></span><BR>
<span id="display5"></span><BR>