SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: code probs

  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    code probs

    Code:
    <body onLoad="javascript:doMenu(false)">
    <script language="JavaScript">
    
    function doMenu(tf) {
    	document.write("<table><tr><td>");
    	document.write("<a onClick=\"javascript:doMenu(true)\">Main Menu</a></td></tr>");
    	if (tf == true) {
    		document.write("<tr><td><a OnMouseOver=\"javascript:dropMenu(true)\">SubMenu</a></td></tr>");
    	} else {
    		document.write("<tr><td></td></tr>");	
    	}
    	document.write("</table>");
    }
    function dropMenu(trfa) {		
    	document.write("<table><tr><td>");
    	document.write("<a onClick=\"javascript:doMenu(true)\">Main Menu</a></td></tr>");
    	document.write("<tr><td><a OnMouseOver=\"javascript:dropMenu(true)\">SubMenu</a></td></tr>");
    	if (trfa == true) {
    		document.write("<tr><td><a href=\"http://www.google.de\">Google</a></td></tr>");
    	} else {
    		document.write("<tr><td></td></tr>");
    	}
    	document.write("</table>");
    }
    </script>
    Get Error: Oject expected.


    Don't know why this doesn't work ...

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    remove the javascript: from the onmouseover and onclicks.

    Javascript: is only needed when accessing javascript as a Link ie

    <a href="javascript:blah()">test</a>

    or typing directly into the browser window:

    javascript:blah();


  3. #3
    SitePoint Member GreboGuru's Avatar
    Join Date
    Jun 2006
    Location
    Wensleydale, UK
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The document.write is destroying the document. If I use the code provided the resulting HTML in FF is

    HTML Code:
    <html><head></head><body><table><tbody><tr><td>
    <a href="#" onclick="doMenu(true)">Main Menu</a></td></tr><tr><td></td>
    </tr></tbody></table></body></html>
    No functions, nowt ......
    Last edited by GreboGuru; Nov 7, 2006 at 05:44.
    Is lunch here?

  4. #4
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I played around a while and have some different code ... I have a kind of menu with 3 levels ... first level is main_links ... second level are the sub links of the main links ... and third level are the real links of the sub links(level 2) ... so instead using a db a wrote some arrays to have some values but my code doesn't work ... have no idea what's going on ... maybe someone of you find the mistake

    Code:
    <head>
    <script language="JavaScript">
    function doMenu() {
    	var main_links = new Array('MainLink1','MainLink2');
    	
    	var sub_links['MainLink1'] = new Array('SubLink11','SubLink12','SubLink13');
    	var sub_links['MainLink2'] = new Array('SubLink21','SubLink22','SubLink23');
    	
    	var links['MainLink1']['SubLink1'] = new Array('Google111','Google112','Google113');
    	var links['MainLink1']['SubLink2'] = new Array('Google121','Google122','Google123');
    	var links['MainLink1']['SubLink3'] = new Array('Google131','Google132','Google133');
    	var links['MainLink2']['SubLink1'] = new Array('Google211','Google212','Google213');
    	var links['MainLink2']['SubLink2'] = new Array('Google221','Google222','Google223');
    	var links['MainLink2']['SubLink3'] = new Array('Google231','Google232','Google233');
    	
    	var i = 0;
    	var x = 0;
    	var y = 0;
    	location.reload();
    	
    	while (i < 2) {	
    		document.write("<td><a onMouseOver=\"javascript:document.write('<table><tr><td>" + main_links[i] + "</td></tr><tr>");
    		while (x < 3) {
    			document.write("<td>" + sub_links[main_links[i]][x] + "</td>");	
    			document.write("</tr><tr>");
    			while (y < 3) {
    				document.write("<td><a href=http://www.google.de>" + links[main_links[i]][sub_links[x]][y] + "</a></td><td>&nbsp;</td><td>&nbsp;</td></tr></table>')\">" + sub_links[main_links[i]][x] + "</a></td>");
    				y++;
    			}
    			x++;
    		}
    		document.write("</tr></table>");
    		i++;
    	}	
    }
    </script>
    </head>
    <body>
    <script language="JavaScript">
    document.write("<table><tr><td>");
    document.write("<a onClick=\"javascript:doMenu()\">Main Menu</a></td></tr>");	
    </script>


Bookmarks

Posting Permissions

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