...

View Full Version : dyanmic drop down menu unknown errors



reubenb
02-03-2005, 03:20 AM
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


<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

hemebond
02-03-2005, 04:35 AM
funtion myfunc()
{
...
}You need to pay attention to your use of {} (or lack thereof in this case).

reubenb
02-03-2005, 05:56 AM
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?

glenngv
02-03-2005, 06:15 AM
"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.

reubenb
02-03-2005, 07:00 AM
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.



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

hemebond
02-03-2005, 07:19 AM
None of your if statements have an opening {

reubenb
02-03-2005, 07:30 AM
<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?

Brandoe85
02-03-2005, 07:42 AM
Your if's are wrong...
if() {
//do something
}

reubenb
02-03-2005, 07:48 AM
like that?
still says that an object is expected on the onChange="... line.



if (subcat[x,1] == selecteditem) {

var option0 = new Option(subcat[x,0], subcat[x,2])
inform.subcategory.options[inform.subcategory.length]=option0
}

glenngv
02-03-2005, 12:22 PM
You have a function and a global variable named subcat. Change one of them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum