Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays

Status
Not open for further replies.

bobbybrown69

Programmer
Jun 11, 2003
15
US
I need to know if the value of elms is Null and if Null don't include it in the array. For example if the value of elms["liner_Year4_" + vid] is Null do not include it in the array. Does anyone know how to do this?

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
];
 
You can try something like this:

Code:
var elms = document.forms[0].elements; 
var lts = new Array(), li = 0;
var ellist = ["Year4", "Year2", "Make", "Model", "Series", "BodyStyle", "VINFull", "VINLast8", "Miles", "RetailPrice", "InternetPrice", "StockNum"];

for (var ei = 0; ei < ellist.length; ei++)
  {
  var onestyle = elms['liner_' + ellist[ei] + '_' + vid].style;
  if (onestyle != null)
    {
    lts[li] = onestyle;
    li++;
    }
  }

Lee
 
Controlling .style would not eliminate the problem of the element being inexistent which in this context would provoke runtime page error. If the element exists, style object always does. Hence it would be better script it like this controlling the element itself.
[tt]
for (var ei = 0; ei < ellist.length; ei++)
{
var oneelem = elms['liner_' + ellist[ei] + '_' + vid];
if (oneelem)
{
lts[li] = oneelem.style;
li++;
}
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top