dynamic dropdown menu

A

Aram

I am making the admin section of a store. This part is for adding
products and there are two drop down menus:

The first is a new Product's MAIN category and the next drop down is
the new Product's SUB category.

The problem I run into is if I am passing the Main category's NAME (a
text value) it works fine. But I need to pass the Main categories ID
(a numerical value) and I get an error:

document.track.names.options.0 is null or not an object

Any reason why a text value would work fine but a numerical one would
cause an error?

THE CODE IS BELOW - if you replace the numbers (10001, 10002, etc.)
in the "showlinks" function with text, the script works fine:

<HTML>
<HEAD><SCRIPT LANGUAGE="JavaScript"><!--
function reshow(object) {
artist = object.options[object.selectedIndex].text;
{
for (var i = document.track.names.length;i > 0;i--)
document.track.names.options[1] = null;
reloading = true;
showlinks();
document.track.names.options[1].selected = true;
theForm.intCatalogID.value=
object.options[object.selectedIndex].text;
}
return false;
}


function load(object) {
theForm.strSubCatalogID.value=
object.options[object.selectedIndex].value;
return false;
}

function showlinks() {

if (artist == '10001') {
opt('Beds','Beds');
opt('Armoires','Armoires');
opt('Dressers','Dressers');

}
if (artist == '10002') {
opt('Loveseats','Loveseats');
opt('Sofas','Sofas');
opt('Coffee Tables','Coffee Tables');
opt('End Tables','End Tables');

}
if (artist == '10003') {
opt('TV Stands','TV Stands');
opt('Entertainment Armoires','Entertainment Armoires');

}
if (artist == '10004') {
opt('Computer Carts','Computer Carts');
opt('Chairs','Chairs');
opt('Computer Deskss','Computer Deskss');
opt('Computer Hutches','Computer Hutches');

}
if (artist == '10005') {
opt('Dining Tables','Dining Tables');
opt('Buffett','Buffett');
opt('China Cabinets','China Cabinets');

}


}

function opt(href,text) {
if (reloading) {
var optionName = new Option(text, href, false, false)
var length = document.track.names.length;
document.track.names.options[length] = optionName;
}
else
document.write('<OPTION VALUE="',href,'">',text,'<\/OPTION>');
}
//--></SCRIPT>

</HEAD>
<BODY>
<p><CENTER>

<B>Select an Artist</B>
<FORM NAME="artists">
<SELECT NAME="artist" onChange="return
reshow(document.artists.artist)" size="1">
<option selected>Choose One:</option>


<OPTION value="10001">Bedroom Furniture
</OPTION>

<OPTION value="10002">Living Room Furniture
</OPTION>

<OPTION value="10003">Entertainment Furniture
</OPTION>

<OPTION value="10004">Office Furniture
</OPTION>

<OPTION value="10005">Dining Room Furniture
</OPTION>

</SELECT>
</FORM>

<SCRIPT LANGUAGE="JavaScript"><!--
var reloading = false;
var artist = document.artists.artist.options[0].text;

{
document.write('<B>Select a track<\/B>');
document.write('<FORM NAME="track">');
document.write('<SELECT NAME="names" onChange="return
load(document.track.names)">');
showlinks();
document.write('<\/SELECT>');
document.write('<\/FORM>');
}
//--></SCRIPT>

<form method="POST" action="send.asp" name="theForm">

main<input type="text" name="intCatalogID" size="40" value=""><br>
subcat<input type="text" name="strSubCatalogID" size="40" value="">


</form>
</CENTER></BODY></HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,367
Latest member
Monarch

Latest Threads

Top