SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Location
    Sri Lanka
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Second call to fuction gives object required error

    Hi I'm New to Javascript so sorry if I'm being Silly

    I'm trying to build a cascading menu in javascript I got as far as this ; all I want to do is Re-draw the whole page when the link is clicked however I get an object required message the second time the link is clicked (I,m using IE 5)

    -----------------------
    <script language=javascript>


    function drawtable() {
    // draw the table


    document.write ("<TABLE cellspacing=\"0\" border=\"1\" cellpadding=\"0\" bordercolor=\"#000000\">") ;

    for (var i = 0 ; i < MainMenu.length ; i++ ) {

    document.write("<TR><TD bgcolor=\"#999966\">");
    document.write("<FONT size=2 face=\"Verdana\" color=\"#000000\">") ;
    document.write(MainMenu[i]) ;
    document.write("</FONT></TD></TR>");

    }

    document.write("</TABLE>") ;

    document.write("<A href=\"dummy.html\" onclick=\"Javascript:drawtable();return false\">Click here</A>") ;


    }

    // array to store the menu items

    var MainMenu = new Array ("Main Menu Item 1",
    "Main Menu Item 2",
    "Main Menu Item 3",
    "Main Menu Item 4",
    "Main Menu Item 5",
    "Main Menu Item 6") ;



    </script>

    <HTML><HEAD>

    <BODY>

    <A href="dummy.html" onclick="Javascript:drawtable();return false">Click here</A>


    </BODY></HTML>


    -------------------------------

    Thanx In advance
    Last edited by ArjunaK; Feb 21, 2002 at 14:37.

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works for me, try that.


    <script language=javascript>

    function drawtable() {
    // draw the table

    document.write ("<TABLE cellspacing=\"0\" border=\"1\" cellpadding=\"0\" bordercolor=\"#000000\">") ;

    for (var i = 0 ; i < MainMenu.length ; i++ ) {

    document.write("<TR><TD bgcolor=\"#999966\">");
    document.write("<FONT size=2 face=\"Verdana\" color=\"#000000\">") ;
    document.write(MainMenu[i]) ;
    document.write("</FONT></TD></TR>");

    }

    document.write("</TABLE>") ;

    document.write("<A href=\"dummy.html\" onclick=\"javascript:drawtable();return false\">Click here</A>");

    }

    // array to store the menu items

    var MainMenu = new Array ("Main Menu Item 1",
    "Main Menu Item 2",
    "Main Menu Item 3",
    "Main Menu Item 4",
    "Main Menu Item 5",
    "Main Menu Item 6") ;

    </script>

    <HTML><HEAD>

    <BODY>

    <A href="dummy.html" onclick="javascript:drawtable();return false">Click here</A>

    </BODY></HTML>

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sry I just realised what you was trying todo

    well, heres a tip.

    when you click the button once. It write's

    <TABLE cellspacing="0" border="1" cellpadding="0" bordercolor="#000000">

    <TR>
    <TD bgcolor="#999966"><FONT size=2 face="Verdana" color="#000000">Main Menu Item 1</FONT></TD>
    </TR>

    <TR>
    <TD bgcolor="#999966"><FONT size=2 face="Verdana" color="#000000">Main Menu Item 2</FONT></TD>
    </TR>

    <TR>
    <TD bgcolor="#999966"><FONT size=2 face="Verdana" color="#000000">Main Menu Item 3</FONT></TD>
    </TR>

    <TR>
    <TD bgcolor="#999966"><FONT size=2 face="Verdana" color="#000000">Main Menu Item 4</FONT></TD>
    </TR>

    <TR>
    <TD bgcolor="#999966"><FONT size=2 face="Verdana" color="#000000">Main Menu Item 5</FONT></TD>
    </TR>

    <TR>
    <TD bgcolor="#999966"><FONT size=2 face="Verdana" color="#000000">Main Menu Item 6</FONT></TD>
    </TR>
    </TABLE>

    <A href="dummy.html" onclick="javascript:drawtable();return false">Click here</A>

    so theres no function to be called on that page.
    Last edited by Andrew-J2000; Feb 22, 2002 at 00:38.

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Do you want it to do this?

    <script language=javascript>

    function drawtable() {
    // draw the table

    document.write ("<TABLE cellspacing=\"0\" border=\"1\" cellpadding=\"0\" bordercolor=\"#000000\">") ;

    for (var i = 0 ; i < MainMenu.length ; i++ ) {

    document.write("<TR><TD bgcolor=\"#999966\">");
    document.write("<FONT size=2 face=\"Verdana\" color=\"#000000\">") ;
    document.write(MainMenu[i]) ;
    document.write("</FONT></TD></TR>");

    }

    document.write("</TABLE>") ;

    document.write("<A href=\"dummy.html\">Click here</A>");

    }

    // array to store the menu items

    var MainMenu = new Array ("Main Menu Item 1",
    "Main Menu Item 2",
    "Main Menu Item 3",
    "Main Menu Item 4",
    "Main Menu Item 5",
    "Main Menu Item 6") ;

    </script>

    <HTML><HEAD>

    <BODY>

    <A href="dummy.html" onclick="javascript:drawtable();return false">Click here</A>

    </BODY></HTML>


    or do you want javascript to call another function?

  5. #5
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You know, a cascading menu probably isn't a good place to start learning javascript. You should try to make smaller scripts until you understand how the language works better. Then you'll have a better idea of how to go about making a cascading menu.
    ck :: bringing chris to the masses.

  6. #6
    SitePoint Member
    Join Date
    Jan 2002
    Location
    Sri Lanka
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Fix one problem and another pops up

    Thanks Andrew for helping me out

    What you are saying is that document.write() overwrites the whole page. (correct me if I'm wrong) .

    What I'm trying to do is to redraw the whole menu with each click (I was planning on putting in the sub menus later)

    I've got a fix that works but brings up another problem

    What I did is I moved the javascript to a separate file. I don't get any errors anymore however when the menu gets redrawn the original stuff is still there!!

    HELP Please!

    Here are the files

    HTML
    --------------------------------
    <script language="javascript" src="functions.js">
    </script>


    <HTML><HEAD></head><BODY>

    <A href="dummy.html" onclick="javascript:drawtable();return false">Click here</A>


    </BODY></HTML>

    --------------------------------------
    Javascript
    ------------------------------------

    // array to store the menu items

    var MainMenu =
    new Array ("Main Menu Item 1",
    "Main Menu Item 2",
    "Main Menu Item 3",
    "Main Menu Item 4",
    "Main Menu Item 5",
    "Main Menu Item 6") ;


    function drawtable() {
    // draw the table

    document.write ("<script language=\"JavaScript\" src=\"functions.js\">") ;
    document.write ("</script>") ;

    document.write ("<HTML><HEAD></head><BODY>") ;

    document.write ("<TABLE cellspacing=\"0\" border=\"1\" cellpadding=\"0\" bordercolor=\"#000000\">") ;

    for (var i = 0 ; i < MainMenu.length ; i++ ) {

    document.write("<TR><TD bgcolor=\"#999966\">");
    document.write("<FONT size=2 face=\"Verdana\" color=\"#000000\">") ;
    document.write(MainMenu[i]) ;
    document.write("</FONT></TD></TR>");

    }

    document.write("</TABLE>") ;

    document.write("<A href=\"dummy.html\" onclick=\"javascript:drawtable();return false\">Click here</A>") ;

    document.write ("</BODY></HTML>") ;

    }

    --------------------------

    BTW Anachros I'm new to Javascript but have worked with Java before, and I've allready built a working pop up menu in Javascript . thought I could try and see if I could do this .

    I've actualy got this working in PHP so have a good Idea of what I want.

    Thanks All.


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
  •