Click to See Complete Forum and Search --> : Passing parameters
toonist
04-18-2003, 12:27 PM
I am building a slide show using Java script in an HTML page and I need to pass it a parameter.
The idea is to start the show at a particular image rather than at the first one.
How can I pass a variable from one HTML page to a javacsipt in the HTML page that it links to?
Can anybody help?
Thanks in advance.
Toonist
khalidali63
04-18-2003, 01:31 PM
Here is how.
1. create the following javascript area in the head section( between the <head> tags)
<script type="text/javascript">
funtion changeImg(url){
var img = new Image();
img.src = url;
alert("you want to change this image\n"+img.src);
}
</script>
then in the html part you'll have something like this
<img src="someImage.gif" onclick="changeImg('newimage.gif')">
hope this helps
toonist
04-19-2003, 08:42 AM
Thank you Khalid, I dont think this would do. But I saw your answer to JSchwarz on 04 14 and it gave me an idea.
I am attaching the guts of the slide show code.
I want to come from a parent page and set the variable "thisImg" and the image I call "slideshow" to a particular value that will depend on where I am on the parent page.
How can I do that?
Thank you in advance.
========================
captionText = new Array( "Rose",.......)
thisImg = 0
imgCt = captionText.length/2
function newSlide(direction) {
if (document.images) {
thisImg = thisImg + direction
if (thisImg < 0) {
thisImg = imgCt-1
}
if (thisImg == imgCt) {
thisImg = 0
}
document.slideshow.src = "images/photos/slideImg" + thisImg + ".jpg"
document.ImgForm.ImgText.value = captionText[thisImg*2]
document.ImgForm.ImgTextTry.value = captionText[(thisImg*2)+1] }
}
===============================
<BODY onLoad="document.ImgForm.ImgText.value = captionText[thisImg], document.ImgForm.ImgTextTry.value = captionText[thisImg+1]">
....
<IMG BORDER="0" SRC="images/photos/slideImg0.jpg" NAME="slideshow"> </TD>
<FORM NAME="ImgForm">
<IMG SRC="images/buttons/arrw0740.gif" onClick="newSlide(-1)">
<INPUT TYPE=TEXT NAME="ImgText" size="60" READONLY class = Caption>
<IMG SRC="images/buttons/arrw0741.gif" onClick="newSlide(1)"><BR>
<INPUT TYPE=TEXT NAME="ImgTextTry" size="80" READONLY class = Caption ></TEXTAREA>
</FORM>
David Harrison
04-19-2003, 09:00 AM
Well I don't know about the source you've written (I didn't have the time to read through much of it) but I know what I'd do. The attachment is a zipped copy of one of Dave Clark's source's that he told me about when I wanted to pass some values from one page to another.
You enter some values in a text box and on the next page it get's them from the address bar and displays them on the page. This source can easily be modified to do what you want, you could get the value from the address bar and have a function that add's 1 to it and takes you to the same page but with a different picture on it, or something along those lines.
I'm not too good at writing sources but I can modify them easily, so if you're not too sure what something does, ask me cause I've been playing around with it for a while, it might be better to ask Dave Clark himself of course.
Any way, sorry if this is no help at all but I hope it is.
Oh, by the way, check out the original post at http://forums.webdeveloper.com/showthread.php?s=&threadid=7288, it might answer some of your questions before you ask them.