Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts

    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 :)

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    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]

  • #3
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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
    Last edited by canadianjameson; 10-24-2005 at 04:37 AM.
    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 :)

  • #7
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    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

  • #8
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •