I have made a drop down list that is populated with months. However, I keep getting the word 'undefined' appearing in the drop down list too. Any help is appreciated. Thanks.
// JavaScript Document
var month = '\
January:January|\
February:February|\
March:March|\
April:April|\
May:May|\
June:June|\
July:July|\
August:August|\
September:September|\
October:October|\
November:November|\
Decemberecember|\
';
// Save the month & state field names
var monthFieldCfgArray = document.getElementById('cs_config_month_field').value.split(' ');
// Save the names of the fields that hold the month & state default values
var monthDefaultCfgArray = document.getElementById('cs_config_month_default').value.split(' ');
var defaultMonth = false;
function TrimString(sInString) {
if ( sInString ) {
sInString = sInString.replace( /^\s+/g, "" );// strip leading
return sInString.replace( /\s+$/g, "" );// strip trailing
}
}
// Populates the month select with the months from the month list
//
function populateMonth(idName) {
var monthLineArray = month.split('|'); // Split into lines
var selObj = document.getElementById( idName );
selObj.options[0] = new Option('Month','');
selObj.selectedIndex = 0;
for (var loop = 0; loop < monthLineArray.length; loop++) {
lineArray = monthLineArray[loop].split(':');
monthCode = TrimString(lineArray[0]);
monthName = TrimString(lineArray[1]);
if ( monthCode != '' ) {
selObj.options[loop + 1] = new Option(monthName, monthCode);
}
if ( defaultMonth == monthCode ) {
selObj.selectedIndex = loop + 1;
}
}
}
// Initialize the drop downs
//
function initMonth() {
for (var loop = 0; loop < monthFieldCfgArray.length; loop++) {
monthIdName = monthFieldCfgArray[loop];
// Read the default value hidden fields
defaultMonth = document.getElementById( monthDefaultCfgArray[loop] ).value;
populateMonth( monthIdName);
}
}
// JavaScript Document
var month = '\
January:January|\
February:February|\
March:March|\
April:April|\
May:May|\
June:June|\
July:July|\
August:August|\
September:September|\
October:October|\
November:November|\
Decemberecember|\
';
// Save the month & state field names
var monthFieldCfgArray = document.getElementById('cs_config_month_field').value.split(' ');
// Save the names of the fields that hold the month & state default values
var monthDefaultCfgArray = document.getElementById('cs_config_month_default').value.split(' ');
var defaultMonth = false;
function TrimString(sInString) {
if ( sInString ) {
sInString = sInString.replace( /^\s+/g, "" );// strip leading
return sInString.replace( /\s+$/g, "" );// strip trailing
}
}
// Populates the month select with the months from the month list
//
function populateMonth(idName) {
var monthLineArray = month.split('|'); // Split into lines
var selObj = document.getElementById( idName );
selObj.options[0] = new Option('Month','');
selObj.selectedIndex = 0;
for (var loop = 0; loop < monthLineArray.length; loop++) {
lineArray = monthLineArray[loop].split(':');
monthCode = TrimString(lineArray[0]);
monthName = TrimString(lineArray[1]);
if ( monthCode != '' ) {
selObj.options[loop + 1] = new Option(monthName, monthCode);
}
if ( defaultMonth == monthCode ) {
selObj.selectedIndex = loop + 1;
}
}
}
// Initialize the drop downs
//
function initMonth() {
for (var loop = 0; loop < monthFieldCfgArray.length; loop++) {
monthIdName = monthFieldCfgArray[loop];
// Read the default value hidden fields
defaultMonth = document.getElementById( monthDefaultCfgArray[loop] ).value;
populateMonth( monthIdName);
}
}