| Intro Passing Data | Name & Value Muliple Elements | Variable & Value | Data to Popup Data from Popup | OpenerArrays | Form Method |
1) Pass set values contained in the script
In the calling document.
<script type="text/javascript">
<!--
function passData(){
var sum=3*5
var str="Data Passed To Document"
+"<P>A B C D E "
+"<P>1 2 3 4 5"
+"<P>" + sum;
location.href = 'page2.htm' + '?' + str
//window.open('page2.htm' + '?' + str,'win1','left=300,top=100,width=300,height=300')
}
//-->
</script>
<a href="#null" onclick="passData();return false">Pass Data</a>
In the called document. (page2.htm) : This is used for all the examples on this page.
<script type="text/javascript"> <!-- var dataPassed = '' if (location.search.length > 0) dataPassed = unescape(location.search.substring(1)) document.write(dataPassed) //--> </script>
2) Pass set values contained in the link In the following example the link passes the url and the data to the function.
<script type="text/javascript">
<!--
function passData2(url,data){
var str=data
location.href = url + '?' + str
//window.open(url + '?' + str,'win1','left=300,top=100,width=300,height=300')
}
//-->
</script>
<a href="#null" onclick="passData2('page2.htm','Hello World');return false">Pass Data2</a>
3) Pass set values in form elements
The script in the this page.
<script type="text/javascript">
<!--
function passData3(string) {
location.href = "page2.htm" + '?' + string
}
//-->
</script>
<form name="f1">
<input name="t1" type="text">
<input type="button" value ="Pass Data" onclick="passData3(this.form.t1.value)">
</form>