Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-22-2005, 09:52 PM   PM User | #1
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
is it possible to pass a JS variable through a link to a second page?

ugly title.

okay. i have a products page here: www.enviromark.ca/english/products.html
on that page i have a list of product manufacturers. when a user runs the mouse over a name of a manufacturer, or clicks it, it shows the products made by that manufacturer.

that is acheived by this little bit of code (for ex: )
Code:
onmouseover="changetext(content[5]);"
my question this... can i have a link on another page saying
"Click here to view the XYZ company products", and have it not only link to the products page, but also open the "content[5]" onload?

so something like
Code:
<a href="products.html;content[5]">Click here to view the XYZ company products</a>
is it even possible??
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 10-22-2005, 10:29 PM   PM User | #2
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
You can use a location.search ("?")
<a href="products?valueOFvariable">

if i.e. Content[5] is equal to "T_Shirt"
then then line must be:
<a href="products?T_Shirt">


and on the produts page put:
Code:
LS=location.search;
TransferValue=LS.substring(1,LS.length)
;

then TransferValue will be equal to Content[5]
Lerura is offline   Reply With Quote
Old 10-23-2005, 05:52 PM   PM User | #3
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
Quote:
Originally Posted by lerura
You can use a location.search ("?")
<a href="products?valueOFvariable">

if i.e. Content[5] is equal to "T_Shirt"
then then line must be:
<a href="products?T_Shirt">


and on the produts page put:
Code:
LS=location.search;
TransferValue=LS.substring(1,LS.length)
;

then TransferValue will be equal to Content[5]
okay, i like the approach. is this functional in most browsers?

few questions:
Here's a real example: if i had this as my link:
Code:
<a href="products.html?content[5]">Click here to view Multifor's products</a>
where on the products page would i put
Code:
LS=location.search;
TransferValue=LS.substring(1,LS.length)
also, what i'm not seeing is the "TransferValue" usage... because content[5] is the actual part of the array i wish to load when the page loads.

lemme show you with some truncated code from the products page which you can see in action here: www.enviromark.ca/english/products.html
Code:
<script>
<!--

var content=new Array()
content[0]='<span>Bindicator</span><br><font size="1">(Celtek Electronics)</font><hr size=1><ul><li><a href="javascript:newWinPDF(\'prodInfo/Bindicator/Phase_Tracker.pdf\');">Phase Tracking</a> continuous level monitoring (Dry and Liquids)</li><li><a href="javascript:newWinPDF(\'prodInfo/Bindicator/loadCell_SpecSheet.pdf\');">Load Cells</a>, yo-yos, etc</ul>'
content[1]='... etc, you get the point'
...
..
.
content[10]...

function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers){
appear()
setTimeout("window.onresize=regenerate",450)
}
}

function changetext(whichcontent){
  if (document.getElementsByTagName) {
    for(var i = 0;i < fading.length;i++){ 
      clearTimeout(fading[i]);  
      }
    }
  if (document.all||document.getElementById){
    cross_el=document.getElementById? document.getElementById("descriptions"):document.all.descriptions
    cross_el.innerHTML=whichcontent
    }
  else if (document.layers){
    document.d1.document.d2.document.write(whichcontent)
    document.d1.document.d2.document.close()
    }
  initLinkFade();
  }
glueHand=changetext;
function nullFunk(){return null};
mousetime=null;

function yarnFace(witchcontent){
  changetext=nullFunk;
  clearTimeout(mousetime);
  glueHand(witchcontent);
  mousetime=setTimeout('countDown(5)',0);
  }

function countDown(n){
  if(!n){
    changetext=glueHand;
    document.getElementById('countD').style.visibility='hidden'
    }
  else{
    document.getElementById('countD').style.visibility='visible'
    document.getElementById('countD').innerHTML=n;
    mousetime=setTimeout('countDown('+(n-1)+')',1000);
    }
  }
  
function appear(){
document.d1.visibility='show'
}

if (document.layers){
window.onload=regenerate2
}

//-->
</script>

...
</head>

....
 <div id="scriptmenu" class="dynamicLinks"> 
            <table cellspacing=0 cellpadding=0 width="70%" align=center border=0>
              <tbody>
          			      <tr>
                                <TD vAlign=top><IMG height=6 alt="" hspace=5 
                                src="images/bull.gif" width=6 vspace=5 
                                border=0></TD>
			                    <TD><span class="link2describe"
                                onmouseover="status='Bindicator Products';changetext(content[0]);" 
                                onmouseout="status=' '" 
                                onclick="yarnFace(content[0])">Bindicator 
                                </span></TD></TR>
                                <TR>
                                <TD colSpan=2>
                                <HR SIZE=1>
                                </TD></TR>
               </tbody>
              </table>
</div>
this is how the script actually works.

so again. where do i place the code on the products.html page and do i need to modify it at all?
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 10-23-2005, 09:38 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,448
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
See http://javascript.about.com/library/blqs.htm for an explanation of how to pass variables between pages using Javascript.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 10-24-2005, 02:19 AM   PM User | #5
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
in that case change the script to:
Code:
LS=location.search;
TransferValue=eval(LS.substring(1,LS.length))
and put it
Code:
content[1]='... etc, you get the point'
...
..
.
content[10]...
 Here
function regenerate(){
window.location.reload()
}
function regenerate2(){
right after the creation of the array.

Then TransferValue will be equal to content[5] in products.html

Last edited by Lerura; 10-24-2005 at 02:22 AM..
Lerura is offline   Reply With Quote
Old 10-24-2005, 04:20 AM   PM User | #6
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
lemme try it

k, it didnt open the content[5]

heres what i did: on index.html i put
Code:
<a href="products.html?content[5]">Click here to view Multifor's products</a>
and on the products.html page i put

Code:
content[10] ...


LS=location.search;
TransferValue=eval(LS.substring(1,LS.length))

function regenerate(){
window.location.reload()
...
i put up mock links so you could see and maybe get a better feel.
www.enviromark.ca/english/indexTest.html --> bottom of page(ish) "Click here .. Multifor"
www.enviromark.ca/english/productsTest.html
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

Last edited by canadianjameson; 10-24-2005 at 04:37 AM..
canadianjameson is offline   Reply With Quote
Old 10-24-2005, 04:58 PM   PM User | #7
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
you have created the function changetext()

this function can be used for the issue.

replace
Code:
LS=location.search;
TransferValue=eval(LS.substring(1,LS.length))
with
Code:
function onLoadChangetext(){
if (location.search){
LS=location.search;
TransferValue=eval(LS.substring(1,LS.length))
changetext(TransferValue);
}}
and add
Code:
onLoad="onLoadChangetext();"
to your bodytag
Lerura is offline   Reply With Quote
Old 10-25-2005, 03:44 AM   PM User | #8
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
BOOYA!

perfect!!

thats EXACTLY what i wanted!
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:52 AM.


Advertisement
Log in to turn off these ads.