help req for a dumbass

liunx

Guest
Can anyone help. <br />
I want to be able to enter text into a field in a form by clicking a button or image on another page. <br />
Its going to be a shopping basket idea but for free samples ( ie no calculation needed )<!--content-->Maybe this can inspire you:<br />
<br />
Lets say you have this in page1:<br />
<br />
<a href=http://www.htmlforums.com/archive/index.php/"page2.html?item=1">Item 1</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"page2.html?item=2">Item 2</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"page2.html?item=3">Item 3</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"page2.html?item=4">Item 4</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"page2.html?item=5">Item 5</a><br />
<br />
When the user clicks on one of the above links the page will change. In addition an extra piece of information will be appended to the end of the url. Say you click on link item number 4, the url of page2.html will look like this:<br />
<br />
<!-- m --><a class="postlink" href="http://www.yoursite.com/page2.html?item=4">http://www.yoursite.com/page2.html?item=4</a><!-- m --><br />
<br />
If you have a script in the head of page2 you can then extract that information like this:<br />
<script language="javascript"><br />
var url = window.location.href;<br />
var queryStr = url.substring(url.indexOf("?")+1);<br />
// queryStr will be equal to "item=4"<br />
// you can now output this data<br />
document.write(queryStr);<br />
</script><br />
<br />
Or more elaborate information can be send:<br />
<br />
<a href=http://www.htmlforums.com/archive/index.php/"page3.html?form=myform;name=bgates;value=1000">Link a</a><br />
<br />
and you can extract it like this:<br />
<script language="javascript"><br />
var url = window.location.href;<br />
var queryStr = url.substring(url.indexOf("?")+1);<br />
// queryStr = form=myform;name=bgates;value=1000<br />
<br />
var outputAry = new Array();<br />
queryAry = queryStr.split(";");<br />
// queryAry = ["form=myform","name=bgates","value=1000"]<br />
<br />
for (var i=0; i<queryAry.length;i++){<br />
infoAry = queryAry.split("=");<br />
//infoAry = ["form","myform"] when i=0<br />
//infoAry = ["name","bgates"] when i=1<br />
//infoAry = ["value","1000"] when i=2<br />
outputAry = new Array();<br />
outputAry["Key"] = infoAry[0];<br />
//outputAry[0]["Key"] = "form" when i=0<br />
//outputAry[1]["Key"] = "name" when i=1<br />
//outputAry[2]["Key"] = "value" when i=2<br />
outputAry["Value"] = infoAry[1];<br />
//outputAry[0]["Value"] = "myform" when i=0<br />
//outputAry[1]["Value"] = "bgates" when i=1<br />
//outputAry[2]["Value"] = "1000" when i=2<br />
}<br />
<br />
for (var j=0;j<queryAry.length;j++){<br />
document.write("The key is: "+outputAry["Key"]+" - ";<br />
document.write("The Val is: "+outputAry["Value"];<br />
}<br />
<br />
//result:<br />
//The key is: form - the Val is myform<br />
//The key is: name - the Val is bgates<br />
//The key is: value - the Val is 1000<br />
<br />
Other commands which may be interesting in this connection:<br />
you can use eval to create variables in the receiving page,<br />
example:<br />
eval("var "+outputAry["Key"]+" = "+outputAry["Value"]);<br />
// would equal eval("var name=bgates");<br />
// alert(name);<br />
// result: "bgates";<br />
<br />
Note: the outputAry above is a so-called two dimentional array: e.g. the array contain information which itself are arrays.<br />
<br />
Ok, this was a lot of techical stuff, but hope you understod how you can transfer information between pages by appending it to the url of the page name and then extract that data on another page.<!--content-->
 
Back
Top