MayoorPatel
Programmer
Hi there I have a javascript array which is populated by the database
as you can see the array has been populated with 2 elements from the db and they are indexed 4.1 and 4.3 because I deleted 4.2 earlier. The code that reads these arrays and puts together the actual dropdown is here.
[/code]
<script type="text/javascript">
function populate(catSelect,formName,subSelectName,selected)
{
subSelect = eval("document.forms." + formName + "." + subSelectName);
subSelect.options.length = 0;
var catNum = catSelect.options[selected].value;
if (subTextArray[catNum] == null)
{
var noneOption = new Option("-- No Subcategories --", "-1");
subSelect.options[0] = noneOption;
return;
}
var allOption = new Option("-- Choose a Subcategory --", "-1");
subSelect.options[0] = allOption;
for (var i = 1; i < subTextArray[catNum].length; i++)
{
// there might be blank ones, so skip them out
if (subTextArray[catNum] != null)
{
var tmpOption = new Option(subTextArray[catNum], subValueArray[catNum]);
subSelect.options = tmpOption;
}
}
}
</script>
[/code]
as you can see it loops through the arrays and outputs the dropdown. However Because I deleted 4.2 earlier the code does not take account of this and produces this.
which causes me major problems later on, not to mention the fact it looks ugly. Can anyone help me understand how I could ammend my code so that it cuts out the blank lines?
Mayoor
Code:
<script language="Javascript" type="text/javascript">
<!--
var subTextArray = new Array();
var subValueArray = new Array();
subTextArray[4] = new Array();
subValueArray[4] = new Array();
subTextArray[4][1] = "4.1 Agriculture1";
subValueArray[4][1] = 122;
subTextArray[4][3] = "4.3 Agriculture3";
subValueArray[4][3] = 123;
//-->
</script>
as you can see the array has been populated with 2 elements from the db and they are indexed 4.1 and 4.3 because I deleted 4.2 earlier. The code that reads these arrays and puts together the actual dropdown is here.
[/code]
<script type="text/javascript">
function populate(catSelect,formName,subSelectName,selected)
{
subSelect = eval("document.forms." + formName + "." + subSelectName);
subSelect.options.length = 0;
var catNum = catSelect.options[selected].value;
if (subTextArray[catNum] == null)
{
var noneOption = new Option("-- No Subcategories --", "-1");
subSelect.options[0] = noneOption;
return;
}
var allOption = new Option("-- Choose a Subcategory --", "-1");
subSelect.options[0] = allOption;
for (var i = 1; i < subTextArray[catNum].length; i++)
{
// there might be blank ones, so skip them out
if (subTextArray[catNum] != null)
{
var tmpOption = new Option(subTextArray[catNum], subValueArray[catNum]);
subSelect.options = tmpOption;
}
}
}
</script>
[/code]
as you can see it loops through the arrays and outputs the dropdown. However Because I deleted 4.2 earlier the code does not take account of this and produces this.
which causes me major problems later on, not to mention the fact it looks ugly. Can anyone help me understand how I could ammend my code so that it cuts out the blank lines?
Mayoor