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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Adelaide, Australia
    Posts
    472
    Thanks
    3
    Thanked 0 Times in 0 Posts

    dyanmic drop down menu unknown errors

    hi,
    this is my drop down menu script (this is the output from ASP).
    But it is giving me javascript errors - i can't seem to pinpoint on what's wrong.
    Errors are:
    Object Expected
    Code:
    <script language = "JavaScript">
    function subcat()
    cat = document.addchinuch.category[document.addchinuch.category.selectedIndex].value;
    url = "additem.asp?cat="
    url = url + cat;
    window.location.href< = url;
    function sublist(inform, selecteditem)
    inform.subcategory.length = 0 
    
    x = 0
    subcat = new Array();
    subcategorys = "Lots of STUFF!"
    subcategoryof = "1"
    subcategoryid = "1"
    subcat[x,0] = subcategorys;
    subcat[x,1] = subcategoryof;
    subcat[x,2] = subcategoryid;
    if (subcat[x,1] == selecteditem)
    { 
    var option0 = new Option(subcat[x,0], subcat[x,2])
    inform.subcategory.options[inform.subcategory.length]=option0
    x = 1
    subcat = new Array();
    subcategorys = "lots of STUFFwef"
    subcategoryof = "1"
    subcategoryid = "2"
    subcat[x,0] = subcategorys;
    subcat[x,1] = subcategoryof;
    subcat[x,2] = subcategoryid;
    if (subcat[x,1] == selecteditem)
    { 
    var option1 = new Option(subcat[x,0], subcat[x,2])
    inform.subcategory.options[inform.subcategory.length]=option1
    x = 2
    subcat = new Array();
    subcategorys = "lots of STUFFwfe"
    subcategoryof = "1"
    subcategoryid = "3"
    subcat[x,0] = subcategorys;
    subcat[x,1] = subcategoryof;
    subcat[x,2] = subcategoryid;
    if (subcat[x,1] == selecteditem)
    { 
    var option2 = new Option(subcat[x,0], subcat[x,2])
    inform.subcategory.options[inform.subcategory.length]=option2
    x = 3
    subcat = new Array();
    subcategorys = "lots of STFF"
    subcategoryof = "1"
    subcategoryid = "4"
    subcat[x,0] = subcategorys;
    subcat[x,1] = subcategoryof;
    subcat[x,2] = subcategoryid;
    if (subcat[x,1] == selecteditem)
    { 
    var option3 = new Option(subcat[x,0], subcat[x,2])
    inform.subcategory.options[inform.subcategory.length]=option3
    x = 4
    subcat = new Array();
    subcategorys = "egeg"
    subcategoryof = "2"
    subcategoryid = "5"
    subcat[x,0] = subcategorys;
    subcat[x,1] = subcategoryof;
    subcat[x,2] = subcategoryid;
    if (subcat[x,1] == selecteditem)
    { 
    var option4 = new Option(subcat[x,0], subcat[x,2])
    inform.subcategory.options[inform.subcategory.length]=option4
    x = 5
    subcat = new Array();
    subcategorys = "egegegh"
    subcategoryof = "2"
    subcategoryid = "6"
    subcat[x,0] = subcategorys;
    subcat[x,1] = subcategoryof;
    subcat[x,2] = subcategoryid;
    if (subcat[x,1] == selecteditem)
    { 
    var option5 = new Option(subcat[x,0], subcat[x,2])
    inform.subcategory.options[inform.subcategory.length]=option5
    </script>
    
    <body onLoad ="sublist(document.addchinuch,document.addchinuch.category[document.addchinuch.category.selectedIndex].value)">
    
    <form name="addchinuch" action="" method="">
    
    <SELECT id="category" name="category" onChange="sublist(this.form, document.addchinuch.category[document.addchinuch.category.selectedIndex].value)">
    <OPTION selected value=""></OPTION>
    
    <OPTION value="1">Socialism</OPTION>
    
    <OPTION value="2">Social Justice</OPTION>
    
    <OPTION value="3">Reuben</OPTION>
    
    </SELECT>&nbsp;&nbsp;&nbsp;<SELECT id="subcategory" name="subcategory">
    <OPTION selected value="none">-------------------------</option>
    </SELECT>
    
    </form>
    thanks

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    funtion myfunc()
    {
    ...
    }
    You need to pay attention to your use of {} (or lack thereof in this case).

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Adelaide, Australia
    Posts
    472
    Thanks
    3
    Thanked 0 Times in 0 Posts
    oh ok - thanks for that.

    it says there is an object expected on these lines

    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad ="sublist(document.addchinuch,document.addchinuch.category[document.addchinuch.category.selectedIndex].value)">


    <SELECT id="category" name="category" onChange="sublist(this.form, document.addchinuch.category[document.addchinuch.category.selectedIndex].value)">


    what am i missing here?

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    "Object Expected" error usually means the function you're calling does not exist. I checked the spelling and case and they are correct. The problem could still be in your use of { and }. You must have put sublist() function inside the subcat() function, making sublist a local function to subcat. In that case, you can only call sublist inside subcat, thus the object expected error. The solution is to put sublist outside subcat. I suggest you to put indentions in your code to make it readable and easier to debug.

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    Adelaide, Australia
    Posts
    472
    Thanks
    3
    Thanked 0 Times in 0 Posts
    OK - thanks.
    This is what I have got from your recommendations - I think this is what you mean - yes?
    It still gives me the error on that onChange line.

    Code:
    <script language ="JavaScript">
    		
    function subcat()
    {
    cat = document.addchinuch.catagory[document.addchinuch.catagory.selectedIndex].value;
    url = "additem.asp?cat="
    url = url + cat;
    window.location.href< = url;
    }
    
    		function sublist(inform, selecteditem)
    		{
    		inform.subcategory.length = 0 
    
    		x = 0
    		subcat = new Array();
    		subcategorys = "Lots of STUFF!"
    		subcategoryof = "1"
    		subcategoryid = "1"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    
    		if (subcat[x,1] == selecteditem)
    
    		var option0 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option0
    				}
    
    
    		x = 1
    		subcat = new Array();
    		subcategorys = "lots of STUFFwef"
    		subcategoryof = "1"
    		subcategoryid = "2"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    
    		if (subcat[x,1] == selecteditem)
    
    		var option1 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option1
    				}
    
    
    		x = 2
    		subcat = new Array();
    		subcategorys = "lots of STUFFwfe"
    		subcategoryof = "1"
    		subcategoryid = "3"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    
    		if (subcat[x,1] == selecteditem)
    
    		var option2 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option2
    				}
    
    
    		x = 3
    		subcat = new Array();
    		subcategorys = "lots of STFF"
    		subcategoryof = "1"
    		subcategoryid = "4"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    
    		if (subcat[x,1] == selecteditem)
    
    		var option3 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option3
    				}
    
    
    		x = 4
    		subcat = new Array();
    		subcategorys = "egeg"
    		subcategoryof = "2"
    		subcategoryid = "5"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    
    		if (subcat[x,1] == selecteditem)
    
    		var option4 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option4
    				}
    
    
    		x = 5
    		subcat = new Array();
    		subcategorys = "egegegh"
    		subcategoryof = "2"
    		subcategoryid = "6"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    
    		if (subcat[x,1] == selecteditem)
    
    		var option5 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option5
    				}
    
    		}
    </script>
    
    <form name="addchinuch" method="" action="">
    <SELECT id="category" name="category" onChange="sublist(this.form, document.addchinuch.category[document.addchinuch.category.selectedIndex].value)">
    <OPTION selected value=""></OPTION>
    
    <OPTION value="1">Socialism</OPTION>
    
    <OPTION value="2">Social Justice</OPTION>
    
    <OPTION value="3">Reuben</OPTION>
    
    </SELECT>&nbsp;&nbsp;&nbsp;<SELECT id="subcategory" name="subcategory">
    <OPTION selected value="none">-------------------------</option>
    </SELECT></form>
    Last edited by reubenb; 02-03-2005 at 06:15 AM. Reason: mistake

  • #6
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    None of your if statements have an opening {

  • #7
    Regular Coder
    Join Date
    Sep 2002
    Location
    Adelaide, Australia
    Posts
    472
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Code:
    <script language ="JavaScript">
    		
    function subcat()
    {
    cat = document.addchinuch.catagory[document.addchinuch.catagory.selectedIndex].value;
    url = "additem.asp?cat="
    url = url + cat;
    window.location.href< = url;
    }
    
    		function sublist(inform, selecteditem)
    		{
    		inform.subcategory.length = 0 
    
    
    		x = 0
    		subcat = new Array();
    		subcategorys = "Lots of STUFF!"
    		subcategoryof = "1"
    		subcategoryid = "1"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    {
    		if (subcat[x,1] == selecteditem)
    
    		var option0 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option0
    				}
    
    
    		x = 1
    		subcat = new Array();
    		subcategorys = "lots of STUFFwef"
    		subcategoryof = "1"
    		subcategoryid = "2"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    {
    		if (subcat[x,1] == selecteditem)
    
    		var option1 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option1
    				}
    
    
    		x = 2
    		subcat = new Array();
    		subcategorys = "lots of STUFFwfe"
    		subcategoryof = "1"
    		subcategoryid = "3"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    {
    		if (subcat[x,1] == selecteditem)
    
    		var option2 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option2
    				}
    
    
    		x = 3
    		subcat = new Array();
    		subcategorys = "lots of STFF"
    		subcategoryof = "1"
    		subcategoryid = "4"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    {
    		if (subcat[x,1] == selecteditem)
    
    		var option3 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option3
    				}
    
    
    		x = 4
    		subcat = new Array();
    		subcategorys = "egeg"
    		subcategoryof = "2"
    		subcategoryid = "5"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    {
    		if (subcat[x,1] == selecteditem)
    
    		var option4 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option4
    				}
    
    
    		x = 5
    		subcat = new Array();
    		subcategorys = "egegegh"
    		subcategoryof = "2"
    		subcategoryid = "6"
    		subcat[x,0] = subcategorys;
    		subcat[x,1] = subcategoryof;
    		subcat[x,2] = subcategoryid;
    
    {
    		if (subcat[x,1] == selecteditem)
    
    		var option5 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option5
    				}
    
    		}
    </script>
    Still doens't work?

  • #8
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Your if's are wrong...
    if() {
    //do something
    }

  • #9
    Regular Coder
    Join Date
    Sep 2002
    Location
    Adelaide, Australia
    Posts
    472
    Thanks
    3
    Thanked 0 Times in 0 Posts
    like that?
    still says that an object is expected on the onChange="... line.

    Code:
    		if (subcat[x,1] == selecteditem) {
    		
    		var option0 = new Option(subcat[x,0], subcat[x,2])
    		inform.subcategory.options[inform.subcategory.length]=option0
    				}

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    You have a function and a global variable named subcat. Change one of them.


  •  

    Posting Permissions

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