Forum Moderators: open

Message Too Old, No Replies

Declaring var and [object] returned

         

scoobydoo987

4:01 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



I am trying to declare a var and if I do it this way I get proper results.
var lts = document.forms[0].elements["liner_Year4_" + vid].style;
------------------

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;

Bernard Marx

4:19 pm on Sep 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.forms[0].elements["liner_Year4_" + vid].style
..etc

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

scoobydoo987

4:29 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



What I am trying to do is modify this function to allow the alert message to popup. It works fine with one textbox and one element in lts but I need to now allow multiple textboxes to work. I will try your first thought by modifying var lts and see if that works. Let me know if you have another idea after reading this.
-------------------

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);
}

Bernard Marx

5:13 pm on Sep 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What does
lts
represent in this code?

scoobydoo987

5:26 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



lts is the form element(s) background style.

scoobydoo987

5:28 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



actually just the form element(s) style.

scoobydoo987

6:06 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



I am getting close but can't seem to figure out how to make all the form elements in the array have their background color changed. I need this array to work and I don't think I have it correct.

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);
}

scoobydoo987

6:15 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



Got it to work.

Thanks.