Click to See Complete Forum and Search --> : passing values


bulletz
02-05-2003, 11:03 PM
hi.

here's my problem. im not a programmer..i need help.

i have my first page with 5 pictures (each has its own description), i want those descriptions and pictures to be passed to the other page when i clicked a certain button.

how can i pass values from one html page to another?
without using text field.

thanks!!!

khalidali63
02-05-2003, 11:30 PM
you can not pass images to another page,though,you can pass the image name and then redisplay it on the next page,
use
document.location.href="nextPage.html?"+allImageNamesAndTextDataAppendedHere;

cheers

Khalid

bulletz
02-05-2003, 11:34 PM
ok i'll try that.
one more thing, where will i put
"document.location.href....." ?
in the button of the first page?

=)

pyro
02-05-2003, 11:37 PM
I'd use the button to call a function and put the document.location.href... inside your function.

bulletz
02-06-2003, 12:08 AM
hello!

i've uploaded the pages. maybe you guys can check it out, and help me. im still having problems passing the textdata and all that.

link is www.ihavethegift.org/sponsorship.html

then click "sponsor a child"
then click the "sponsor me" btn

LAwebTek
02-06-2003, 12:17 AM
I have a slightly different approach:

page 1 in the <head>:

<script>
function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) +
"; expires=" + expires.toGMTString() + "; path=/";
}

var expdate = new Date();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

function passData(image,data) {
setCookie("imgData", image+"|"+data, expdate);
}
</script>

page 1 <body> for each image:

<a href="page2.html" onClick="passData('image1.gif','my text here')"><img src="image1.gif"></a>

page 2 <head>:

<script>
function getCookie (name) {
var dcookie = document.cookie;
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(" ", cbegin) + 1;
if (cbegin == 0) break;
}
return null;
}

function getData() {
var imgData = getCookie("imgData");
var dataArray = imgData.split("|");
var image = dataArray[0];
var text = dataArray[1];
/* now we have to do something with the stored information, for example, below I will plug in the image and text */
document.all.Pic.style.backgroundImage='url("' + image + '")';
document.capt.text.value = text;
}
</script>

page 2 <body onLoad=getData()> then...

<span id="Pic"><table width="300" height="150"><tr><td>&nbsp;
<!--the table dimensions are set to the image size and assumes all the images will be the same size
but I dont know the specifics of your project!-->
</td></tr></table></span>
<table>
<tr><td>
<form name="capt">
<textarea name="text" cols="35" rows="3"></textarea>
</form>
</td></tr>
</table>

this is not exactly like what you have but it can be made to work for you very easily. Hope it helps!

bulletz
02-06-2003, 12:26 AM
hello!

i've uploaded the pages. maybe you guys can check it out, and help me. im still having problems passing the textdata and all that.

link is www.ihavethegift.org/sponsorship.html

then click "sponsor a child"
then click the "sponsor me" btn

LAwebTek
02-06-2003, 12:26 AM
I just looked at your project and all you would need to do on page 1 is to attach the onClick handler to each button and plug in the appropraite values for the corresponding image path and text. If you use this method and need more help just post :)

bulletz
02-06-2003, 03:44 AM
hi LA webtek!
thanks man...really appreciate your help.
the 1st page is already passing the images and the first TEXT data. another question, how can i add 2 more text data?
(for the name, address of the kids)

LAwebTek
02-06-2003, 10:14 AM
new code for page 1 <head>

<script>
function setCookie (name, value, expires) {
if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) +
"; expires=" + expires.toGMTString() + "; path=/";
}

function setCookieArray(name){
this.length = setCookieArray.arguments.length - 1;
for (var i = 0; i < this.length; i++) {
this[i + 1] = setCookieArray.arguments[i + 1]
setCookie (name + i, this[i + 1], expdate);
}
}

var expdate = new Date();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365));

function passData(image,spNum,name,dob,loc,cntry) {
/*store the data on a cookie*/
storedVal = new Array;
storedVal[1] = image; // image path
storedVal[2] = spNum; // sponsorship #
storedVal[3] = name; // child name
storedVal[4] = dob; // date of birth
storedVal[5] = loc; // location
storedVal[6] = cntry; // country

var testArray = new setCookieArray("imgData", // cookie name
storedVal[1], //array 1 - image
storedVal[2], //array 2 - spNum
storedVal[3], //array 3 - name
storedVal[4], //array 4 - dob
storedVal[5], //array 5 - loc
storedVal[6] //array 6 - cntry
);
}

function moveOn() {
document.location.replace('page2.html');
}
</script>

new page 1 <body>:

<img src="image1.gif" width="150" height="126">
<input type="button" value="Sponsor Me" onClick="passData('image1.gif','ramilgabion001-ph','Ramil Gabion',
'April 16, 1990','RailRoad Track (Makati Area)','Philippines'); moveOn()">

new page 2 <head>

<script>
function getCookie (name) {
var dcookie = document.cookie;
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
while (cbegin < clen) {
var vbegin = cbegin + cname.length;
if (dcookie.substring(cbegin, vbegin) == cname) {
var vend = dcookie.indexOf (";", vbegin);
if (vend == -1) vend = clen;
return unescape(dcookie.substring(vbegin, vend));
}
cbegin = dcookie.indexOf(" ", cbegin) + 1;
if (cbegin == 0) break;
}
return null;
}

function getCookieArray(name){
var i = 0;
while (getCookie(name + i) != null) {
this[i + 1] = getCookie(name + i);
i++; this.length = i;
}
}

var storedVal = new Array;
var dataArray = new getCookieArray("imgData");
function getData() {
getCookie("imgData");
storedVal[1] = ( dataArray[1] ); // image
storedVal[2] = ( dataArray[2] ); // spNum
storedVal[3] = ( dataArray[3] ); // name
storedVal[4] = ( dataArray[4] ); // dob
storedVal[5] = ( dataArray[5] ); // loc
storedVal[6] = ( dataArray[6] ); // cntry
/* plug in the image below */
document.all.Pic.style.backgroundImage='url("' + storedVal[1] + '")';
}

function getText() {
document.write('<b>Sponsorship#: </b>' + dataArray[2] + '<br>' + '<b>Name: </b>' + dataArray[3] + '<br>'
+ '<b>Date of Birth: </b>' + dataArray[4] + '<br>' + '<b>Location: </b>' + dataArray[5] + '<br>'
+ '<b>Country: </b>' + dataArray[6]);
}
</script>

page 2 <body onLoad="getData()">

<table cellpadding="10"><tr><td>
<span id="Pic"><table width="150" height="126"><tr><td>&nbsp;
<!-- the table dimensions are set to the image size !-->
</td></tr></table></span>
</td><td>
<table>
<tr><td>
<script>
getText(); // write the text info
</script>
</td></tr>
</table>
</td></tr>
</table>

bulletz
02-06-2003, 11:47 AM
lawebtek! your the man!
thanks bro, you save me life! =)
i'll definitely include your name and homepage
in the site...credits! =)

one more thing, can i have your email add?
thanks.


million thanks!

LAwebTek
02-06-2003, 05:56 PM
No problem, glad I could help. You can email me at mastermindsink@hotmail.com

If you do mention me in the code, please reference my new site that will be up next month www.LAwebTek.com
(I'm taking the old site down - www.freecashjackpot.com)

Regards,
S. Bishop
LAwebTek

LAwebTek
02-09-2003, 06:19 PM
I sent the attached file in an email through the website, but incase you didnt get it I've posted it here.