#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    19
    Rep Power
    0

    Question function that takes variables from multiple objects (is it pos?)


    Hlo Evry1

    Im reasonably new 2 JS so this question may be kinda ridiculous...(stay with me though plz!)

    ive got a function with 2 variables

    function defineLinks(extension,base){
    window.location.href= base + extension + ".html"
    }


    basicly i have onmouseover menu that changes what pictures appear in an other menu underneath, and the script above should then, when fed the right info, define where the links on the pictures in the bottom menu take u 2.
    The "base" variable should come from the top menu "onmouseover" and the extension shoud come from the bottom menu "onclick" however i can only get one of the variables from each action eg. "base" from the 1st menu and "extension" from the second "appearing" menu and cant therefor put in a simple funtion in the <a> tag in the bottom menu eg.(defineLinks(home,1)) to take me to "home1.html"

    may be kinda beginner but all thats where even great masters start

    Thanks in advance

  2. #2
  3. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    379
    You can split up the function.
    You can then pass the base parameter on the onMouseOver event of the top menu, and set the extension in the onClick event of the bottom menu.
    Code:
    var base;
    function setBase(passedBase) {
      base = passedBase;
    }
    function defineLinks(extension){
      window.location.href= base + extension + ".html"
    }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    19
    Rep Power
    0

    Question gett'n closer, need a little more help plz!


    that sounded like the right thing but gives me the bug "home is not defined".

    Ive included the code i put at the top and bottom menu:

    TOP: <a href="home1.html" onmouseover= "setBase('home');document.linkfi...

    BOTTOM: <a href="javascript:defineLink('1')">

    Any help highly apreciated!

    Luke
  6. #4
  7. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    379
    I don't think this piece of code contains the actual bug. If you could post some more code (between [code] tags please) I'll look into it.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    19
    Rep Power
    0
    Thanks 4 the help m8, its much appreciated!

    here is all of the java in the head and all of what is relevant to the funtion in the body:

    Code:
    <script language="Javascript" type="text/javascript">
    	
    <!--
    
      if (document.images) {
        noLink = new Image
        homeOne = new Image
        homeTwo = new Image
        newsSite = new Image
        companyOverview = new Image
        pagePortfolio = new Image
        pricingPolicy = new Image
        pricingStandard = new Image
        pricingGold = new Image
        pricingPlatinium = new Image
        guaranOne = new Image
        guaranTwo = new Image
        faqOne = new Image
        faqTwo = new Image
        contactUs = new Image
        orderOne = new Image
        orderTwo = new Image
        
        noLink.src = "graphics/noLink.gif"
        homeOne.src = "graphics/homeOne.gif"
        homeTwo.src = "graphics/homeTwo.gif"
        newsSite.src = "graphics/newsSite.gif"
        companyOverview.src = "graphics/companyOverview.gif"
        pagePortfolio.src = "graphics/pagePortfolio.gif"
        pricingPolicy.src = "graphics/pricingPolicy.gif"
        pricingStandard.src = "graphics/pricingStandard.gif"
        pricingGold.src = "graphics/pricingGold.gif"
        pricingPlatinium.src = "graphics/pricingPlatinium.gif"
        guaranOne.src = "graphics/guaranOnegif"
        guaranTwo.src = "graphics/guaranTwo.gif"
        faqOne.src = "graphics/faqOne.gif"
        faqTwo.src = "graphics/faqTwo.gif"
        contactUs.src = "graphics/contactUs.gif"
        orderOne.src = "graphics/orderOne.gif"
        orderTwo.src = "graphics/orderTwo.gif"
        }
      else {		
        noLink = ""
        homeOne = ""
        homeTwo = ""
        newsSite = ""
        companyOverview = ""
        pagePortfolio = ""
        pricingStandard =""
        pricingGold = ""
        pricingPlatnium = ""
        guaranOne = ""
        guaranTwo = ""
        faqOne = ""
        faqTwo = ""
        contactUs = ""
        orderOne = ""
        orderTwo = ""
        document.linkfieldOne = ""
        document.linkfieldTwo = ""
        document.linkfieldThree = ""	
        }
    }
    
      var base;
      function setBase(passedBase) {
        base = passedBase;
      }
    }
    	
      function defineLinks(extension){
        window.location.href= base + extension + ".html"
      }
    	
    // -->
    	
    </script>
    
    </head>
    <body>
    ............
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
           <tr>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="home1.html" onmouseover= "document.linkfieldOne.src=homeOne.src;document.linkfieldTwo.src=homeTwo.src;document.linkfieldThree.src=newsSite.src;linkfieldFour.src=noLink.src;setBase('home')"> 
    <img src="graphics/topbuttonhome1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Home" border="0">
    </a>
            </td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="GI1.html" onmouseover= "document.linkfieldOne.src=companyOverview.src;document.linkfieldTwo.src=pagePortfolio.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;setBase('gi')"> 
    <img src="graphics/topbuttongi1.jpg" hspace="0" vspace="2" height="23" width="118" alt="General Info" border="0">
    </a>
            </td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="pricing1.html" onmouseover= "document.linkfieldTwo.src=pricingStandard.src;document.linkfieldThree.src=pricingGold.src;document.linkfieldFour.src=pricingPlatinium.src;linkfieldOne.src=pricingPolicy.src;setBase('pricing')"> 
    <img src="graphics/topbuttonpricing1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Pricing" border="0">
            </td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="GI1.html" onmouseover= "document.linkfieldOne.src=guaranOne.src;document.linkfieldTwo.src=guaranTwo.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;setBase('guaran')"> 
    <img src="graphics/topbuttonguaran1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Guaranty" border="0">
            </td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="guaran1.html" onmouseover= "document.linkfieldOne.src=faqOne.src;document.linkfieldTwo.src=faqTwo.src;document.linkfieldThree.src=contactUs.src;linkfieldFour.src=noLink.src;setBase('faq')"> 
    <img src="graphics/topbuttonFAQ1.jpg" hspace="0" vspace="2" height="23" width="118" alt="FAQ" border="0">
            </td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center"> 
    <a href="GI1.html" onmouseover= "document.linkfieldOne.src=orderOne.src;document.linkfieldTwo.src=orderTwo.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;setBase('order')"> 
    <img src="graphics/topbuttonorder1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Order!" border="0">
            </td>
           </tr>
           <tr>
            <td bgcolor="silver" colspan="19" height="31">
    <a href="javascript:defineLink('1')">
    <img src="graphics/noLink.gif" name="linkfieldOne" hspace="0" vspace="0" height="17" border="0" width="130"></a>
    <a href="javascript:defineLink('2')">
    <img src="graphics/noLink.gif" name="linkfieldTwo" hspace="0" vspace="0" height="17" border="0" width="130"></a>
    <a href="javascript:defineLink('3')">
    <img src="graphics/noLink.gif" name="linkfieldThree" hspace="0" vspace="0" height="17" border="0" width="130"></a>
    <a href="javascript:defineLink('4')">
    <img src="graphics/noLink.gif" name="linkfieldFour" hspace="0" vspace="0" height="17" border="0" width="130"></a>
            </td>
           </tr>
          </table>
    soz about the long code!!!

    Luke
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    19
    Rep Power
    0
    by the way...the two "parts" of the head tag are really be separated by a

    Code:
    // -->	
    </script>
    <script language="Javascript" type="text/javascript">	
    <!--
    and i dont have all the unneccesary "}" that i put in...
    sry bout that

    luke
  12. #7
  13. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    379
    Hi Luke,

    Maybe if you attached your full code. I can't really debug this if it's not complete. If I try to open it 'as is' I get about a zillion javascript errors.

    What you should do anyway:
    • end javascript lines with a semi-colon where appropriate

    • change new Image to new Image()


    There is probably more, but really can't say more until I have the full code.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    19
    Rep Power
    0

    full code


    here's the full code:

    Code:
    <!doctype html public
    "-//w3c//dtd h
    tml 4.01
    transitional//en
    "http://www.w3.org/tr/html4/loose.dtd">
    
    <html>
    
    <head>
    
    <title>
    page under construction
    </title>
    
    <script language="Javascript" type="text/javascript">
    	
    <!--
    
    	if (document.images) {
    		noLink = new Image()
    		homeOne = new Image()
    		homeTwo = new Image()
    		newsSite = new Image()
    		companyOverview = new Image()
    		pagePortfolio = new Image()
    		pricingPolicy = new Image()
    		pricingStandard = new Image()
    		pricingGold = new Image()
    		pricingPlatinium = new Image()
    		guaranOne = new Image()
    		guaranTwo = new Image()
    		faqOne = new Image()
    		faqTwo = new Image()
    		contactUs = new Image()
    		orderOne = new Image()
    		orderTwo = new Image()
    
    		noLink.src = "graphics/noLink.gif";
    		homeOne.src = "graphics/homeOne.gif";
    		homeTwo.src = "graphics/homeTwo.gif";
    		newsSite.src = "graphics/newsSite.gif";
    		companyOverview.src = "graphics/companyOverview.gif";
    		pagePortfolio.src = "graphics/pagePortfolio.gif";
    		pricingPolicy.src = "graphics/pricingPolicy.gif";
    		pricingStandard.src = "graphics/pricingStandard.gif";
    		pricingGold.src = "graphics/pricingGold.gif";
    		pricingPlatinium.src = "graphics/pricingPlatinium.gif";
    		guaranOne.src = "graphics/guaranOne.gif";
    		guaranTwo.src = "graphics/guaranTwo.gif";
    		faqOne.src = "graphics/faqOne.gif";
    		faqTwo.src = "graphics/faqTwo.gif";
    		contactUs.src = "graphics/contactUs.gif";
    		orderOne.src = "graphics/orderOne.gif";
    		orderTwo.src = "graphics/orderTwo.gif";
    	}
    	else {		
    		noLink = "";
    		homeOne = "";
    		homeTwo = "";
    		newsSite = "";
    		companyOverview = "";
    		pagePortfolio = "";
    		pricingStandard ="";
    		pricingGold = "";
    		pricingPlatnium = "";
    		guaranOne = "";
    		guaranTwo = "";
    		faqOne = "";
    		faqTwo = "";
    		contactUs = "";
    		orderOne = "";
    		orderTwo = "";
    		document.linkfieldOne = "";
    		document.linkfieldTwo = "";
    		document.linkfieldThree = "";
    	}
    
    // -->
    	
    </script>
    
    <script language="Javascript" type="text/javascript">
    	
    <!--
    
    
    	var base;
    	function setBase(passedBase) {
    		base = passedBase;
    	}
    
    	
    	function defineLinks(extension){
      		window.location.href= base + extension + ".html";
    	}
    	
    	
    
    // -->
    	
    </script>
    
    
    </head>
    
    <body 
    	rightmargin="0" 
    	leftmargin="0" 
    	topmargin="0" 
    	bottommargin="0"
    	marginheight="0" 
    	marginwidth="0"
    	link="navy"
    	vlink="black"
    	alink="#B0B3B1"
    	bgcolor="white">
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0">	
     <tr>
      <td>
       <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="silver">
        <tr>
         <td valign="top" align="left" colspan="2">
    <img src="graphics/hgreyline1.bmp" width="100%" height="4" hspace="0" vspace="0"><br>
    <img src="graphics/hgreyline2.bmp" width="100%" height="4" hspace="0" vspace="0"><br>
         </td>
        </tr>
        <tr>
         <td background="graphics/greybg.jpg" valign="top" align="left">
    <img src="graphics/title.gif" height="100" width="448" border="0" hspace="0" vspace="0">
         </td>
         <td background="graphics/greybg.jpg" valign="top" align="right">
    <img src="pictures/w.gif" border="0" hspace="0" vspace="0" height="100" width="100">
         </td>
        </tr>
        <tr>
         <td valign="top" align="left" colspan="2">
    <a onmouseover= "document.linkfieldOne.src=noLink.src;document.linkfieldTwo.src=noLink.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;"><img src="graphics/hgreyline2.bmp" width="100%" height="4" hspace="0" vspace="0"><br>
    <a onmouseover= "document.linkfieldOne.src=noLink.src;document.linkfieldTwo.src=noLink.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;"><img src="graphics/hgreyline1.bmp" width="100%" height="4" hspace="0" vspace="0"><br>  	
         </td>
        </tr>
        <tr align="left">
         <td colspan="2">
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
           <tr>
            <td  width="6" background="tabledesign/topcellleft.bmp"><img src="graphics/transparent2.gif" width="6" height="1"></td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="home1.html" onmouseover= "document.linkfieldOne.src=homeOne.src;document.linkfieldTwo.src=homeTwo.src;document.linkfieldThree.src=newsSite.src;linkfieldFour.src=noLink.src;setBase('home');"> 
    <img src="graphics/topbuttonhome1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Home" border="0">
    </a>
            </td>
            <td  width="6" background="tabledesign/topcellright.bmp"><img src="graphics/transparent.gif" width="6" height="1"></td>
            <td  width="6" background="tabledesign/topcellleft.bmp"><img src="graphics/transparent2.gif" width="6" height="1"></td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="GI1.html" onmouseover= "document.linkfieldOne.src=companyOverview.src;document.linkfieldTwo.src=pagePortfolio.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;setBase('gi');"> 
    <img src="graphics/topbuttongi1.jpg" hspace="0" vspace="2" height="23" width="118" alt="General Info" border="0">
    </a>
            </td>
            <td  width="6" background="tabledesign/topcellright.bmp"><img src="graphics/transparent.gif" width="6" height="1"></td>
            <td  width="6" background="tabledesign/topcellleft.bmp"><img src="graphics/transparent2.gif" width="6" height="1"></td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="pricing1.html" onmouseover= "document.linkfieldTwo.src=pricingStandard.src;document.linkfieldThree.src=pricingGold.src;document.linkfieldFour.src=pricingPlatinium.src;linkfieldOne.src=pricingPolicy.src;setBase('pricing');"> 
    <img src="graphics/topbuttonpricing1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Pricing" border="0">
            </td>
            <td  width="6" background="tabledesign/topcellright.bmp"><img src="graphics/transparent.gif" width="6" height="1"></td>
            <td  width="6" background="tabledesign/topcellleft.bmp"><img src="graphics/transparent2.gif" width="6" height="1"></td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="guaran1.html" onmouseover= "document.linkfieldOne.src=guaranOne.src;document.linkfieldTwo.src=guaranTwo.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;setBase('guaran');"> 
    <img src="graphics/topbuttonguaran1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Guaranty" border="0">
            </td>
            <td  width="6" background="tabledesign/topcellright.bmp"><img src="graphics/transparent.gif" width="6" height="1"></td>
            <td  width="6" background="tabledesign/topcellleft.bmp"><img src="graphics/transparent2.gif" width="6" height="1"></td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center">
    <a href="faq1.html" onmouseover= "document.linkfieldOne.src=faqOne.src;document.linkfieldTwo.src=faqTwo.src;document.linkfieldThree.src=contactUs.src;linkfieldFour.src=noLink.src;setBase('faq');"> 
    <img src="graphics/topbuttonFAQ1.jpg" hspace="0" vspace="2" height="23" width="118" alt="FAQ" border="0">
            </td>
            <td  width="6" background="tabledesign/topcellright.bmp"><img src="graphics/transparent.gif" width="6" height="1"></td>
            <td  width="6" background="tabledesign/topcellleft.bmp"><img src="graphics/transparent2.gif" width="6" height="1"></td>
            <td background="tabledesign/topborder1.bmp" width="16%" align="center"> 
    <a href="order1.html" onmouseover= "document.linkfieldOne.src=orderOne.src;document.linkfieldTwo.src=orderTwo.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;setBase('order');"> 
    <img src="graphics/topbuttonorder1.jpg" hspace="0" vspace="2" height="23" width="118" alt="Order!" border="0">
            </td>
            <td  width="6" background="tabledesign/topcellright.bmp"><img src="graphics/transparent.gif" width="6" height="1"></td>
           </tr>
           <tr>
            <td bgcolor="silver" colspan="19" height="31">
    <a href="javascript:defineLink('1');">
    <img src="graphics/noLink.gif" name="linkfieldOne" hspace="0" vspace="0" height="17" border="0" width="130"></a>
    <a href="javascript:defineLink('2');">
    <img src="graphics/noLink.gif" name="linkfieldTwo" hspace="0" vspace="0" height="17" border="0" width="130"></a>
    <a href="javascript:defineLink('3');">
    <img src="graphics/noLink.gif" name="linkfieldThree" hspace="0" vspace="0" height="17" border="0" width="130"></a>
    <a href="javascript:defineLink('4');">
    <img src="graphics/noLink.gif" name="linkfieldFour" hspace="0" vspace="0" height="17" border="0" width="130"></a>
            </td>
           </tr>
          </table>
         </td>
        </tr>
        <tr>
         <td valign="top" align="left" colspan="2">
    <a onmouseover= "document.linkfieldOne.src=noLink.src;document.linkfieldTwo.src=noLink.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;"><img src="graphics/hgreyline1.bmp" width="100%" height="4" hspace="0" vspace="0"><br>
    <a onmouseover= "document.linkfieldOne.src=noLink.src;document.linkfieldTwo.src=noLink.src;document.linkfieldThree.src=noLink.src;linkfieldFour.src=noLink.src;"><img src="graphics/hgreyline2.bmp" width="100%" height="4" hspace="0" vspace="0"><br>
       </table>
      </td>
     </tr>
     <tr>
      <td 
      	align="center" 
      	valign="bottom">
       <br>
    
      </td>
     </tr>
    </table>
    
    </body>
    
    </html>
  16. #9
  17. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    379
    Ok Luke,

    You can do either of two things:

    1. change the name of function defineLinks to defineLink
    2. change the call from the bottom menu to javascript:defineLinks


    Tested it, and it worked fine.

    BTW: you should also end the something = new Image() lines with a semi-colon.
    Last edited by wsa1971; August 10th, 2004 at 08:29 AM. Reason: forgot something
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    19
    Rep Power
    0
    !!!!!!!nice-1-m8!!!!!!!
  20. #11
  21. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    379
    Glad to be of service

IMN logo majestic logo threadwatch logo seochat tools logo