Forum Moderators: open
But if I try and add to the var (see below) I receive incorrect results. Any idea why I receive this result when adding lts +=
"[object][object][object][object][object][object][object][object][object][object][object][object][object]"
var lts = document.forms[0].elements["liner_Year4_" + vid].style;
lts += document.forms[0].elements["liner_Year2_" + vid].style;
lts += document.forms[0].elements["liner_Make_" + vid].style;
lts += document.forms[0].elements["liner_Model_" + vid].style;
lts += document.forms[0].elements["liner_Series_" + vid].style;
lts += document.forms[0].elements["liner_BodyStyle_" + vid].style;
lts += document.forms[0].elements["liner_VINFull_" + vid].style;
lts += document.forms[0].elements["liner_VINLast8_" + vid].style;
lts += document.forms[0].elements["liner_Miles_" + vid].style;
lts += document.forms[0].elements["liner_RetailPrice_" + vid].style;
lts += document.forms[0].elements["liner_InternetPrice_" + vid].style;
lts += document.forms[0].elements["liner_StockNum_" + vid].style;
lts += document.forms[0].elements["DescriptionAdj_" + vid].style;
These are all references to HTML element style objects. Holding one in a variable is OK, but if you try to "add" them using the + operator you are forcing an implicit type conversion. There is no meaning to (an object) + (another object), so the objects are evaluated as strings (all data types have a string evaluation).
In Internet Explorer, the default string evaluation for most objects is "[object]". In other browsers it will probably be something more informative for document objects.
Do you want them all in an array?
var elms = document.forms[0].elements;
var lts =
[
elms["liner_Year2_" + vid].style,
elms["liner_Make_" + vid].style,
elms["liner_Model_" + vid].style,
elms["liner_Series_" + vid].style,
elms["liner_BodyStyle_" + vid].style,
elms["liner_VINFull_" + vid].style,
elms["liner_VINLast8_" + vid].style,
elms["liner_Miles_" + vid].style,
elms["liner_RetailPrice_" + vid].style,
elms["liner_InternetPrice_" + vid].style,
elms["liner_StockNum_" + vid].style,
elms["DescriptionAdj_" + vid].style
];
var divPreview = eval("divPreview" + vid);
divPreview.innerHTML = newText.replace(/\n/g,"<br>");
if (g_tooLong && lts.backgroundColor == "#ffffff") {
if (alertOnceFlag) {
alert("You have exceeded the character limit for this line.");
alertOnceFlag = false;
}
lts.backgroundColor = "#ff5555";
} else if (!g_tooLong && lts.backgroundColor == "#ff5555") {
lts.backgroundColor = "#ffffff";
}
return(g_lineCount);
}
Works
lts[0].backgroundColor = "#ff5555"
but I want all the elements of the array.
lts[0-11].backgroundColor = "#ff5555" DOESN'T WORK
lts[0,11].backgroundColor = "#ff5555" DOESN'T WORK
------------------------------------
var elms = document.forms[0].elements;
var lts =
[elms["liner_Year4_" + vid].style,
elms["liner_Year2_" + vid].style,
elms["liner_Make_" + vid].style,
elms["liner_Model_" + vid].style,
elms["liner_Series_" + vid].style,
elms["liner_BodyStyle_" + vid].style,
elms["liner_VINFull_" + vid].style,
elms["liner_VINLast8_" + vid].style,
elms["liner_Miles_" + vid].style,
elms["liner_RetailPrice_" + vid].style,
elms["liner_InternetPrice_" + vid].style,
elms["liner_StockNum_" + vid].style
];
var divPreview = eval("divPreview" + vid);
divPreview.innerHTML = newText.replace(/\n/g,"<br>");
if (g_tooLong && lts[0].backgroundColor == "#ffffff") {
if (alertOnceFlag) {
alert("You have exceeded the character limit for this line.");
alertOnceFlag = false;
}
lts[0].backgroundColor = "#ff5555";
} else if (!g_tooLong && lts[0].backgroundColor == "#ff5555") {
lts[0].backgroundColor = "#ffffff";
}
return(g_lineCount);
}