Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing query string variable 1

Status
Not open for further replies.

newimprovedmedia

Technical User
Jun 26, 2001
7
US


I am trying to pass just one variable to an image rotation script, I have read the FAQ on setting variable using a query string, and i know the answer is there but I am still a little confused. Here is my script:
Code:
<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
<!-- Hide code from older browsers
thisImg = 0

function newFolio(direction) {
if (document.images) {
thisImg = thisImg + direction
document.folio.src = &quot;images/&quot; + thisImg + &quot;.jpg&quot;
}
}

// Stop hiding code -->
</script>
</head>

Now I link to the page from an image map and put the query string into the href:
Code:
<a href=&quot;jump.html$thisImg=10&quot;>

And then modify my original script like this:
Code:
                <!-- Hide code from older browsers

  

                  function getQuery(){
                   var queryString = location.search;
                   var data = queryString.slice(1,data_pre.length);
                   for (j=0;j<dataArray.length;j++){
                          thisImg =  eval(dataArray[j])
                    }
                    }
                   
                   

                
                function newFolio(direction) {
                        if (document.images) {
                                thisImg = thisImg + direction
                                document.folio.src = &quot;images/&quot; + thisImg + &quot;.jpg&quot;
                        }
                }
                
                // Stop hiding code -->
                </script>

I am at a loss as to translate the query string into the thisImg variable, and have the main image on the page load using this information. like this?:
Code:
<img src=&quot;onload:newFolio&quot;>

Please Help!,
Web Hack

 
hie
1st: <a href=&quot;jump.html$thisImg=10&quot;> - replace $ by ?
& btw, as u're passin just one parameter, u might write just like this: <a href=&quot;jump.html?10&quot;>
then
in ur popup page:
use smth like this:

<script>
var thisImg=0

function getQuery(){
var queryString = location.search;
var data = queryString.slice(1,queryString.length);
var
thisImg = eval(data)
newFolio(0)
}
onload=getQuery

function newFolio(direction) {
if (document.images) {
thisImg = thisImg + direction
document.images.folio.src = &quot;images/&quot; + thisImg + &quot;.jpg&quot;
}
}
// -->
</script>


2 refer 2 an image u shuld write document.images.imagename or document.images[&quot;imagename&quot;]

regards, vic
 
I get an error if I pass a value that has a space like
href = nextpage.asp?myValue=&quot;this test&quot;
any help would be great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top