Cant get JavaScipt to check for null objects
Posted
by
CountMurphy
on Stack Overflow
See other posts from Stack Overflow
or by CountMurphy
Published on 2012-06-05T22:36:49Z
Indexed on
2012/06/05
22:40 UTC
Read the original article
Hit count: 168
JavaScript
I really don't know what the issue is here. Far as I can see, the code is simple and should work fine.
var Prices="";
for (var PriceCount = 1; PriceCount <= 120; PriceCount++) {
var CurrentPrice = "Price" + PriceCount;
if (prevDoc.getElementById(CurrentPrice).value != null) {
if (Prices == "") {
Prices = prevDoc.getElementById(CurrentPrice).value;
} else {
Prices += "," + prevDoc.getElementById(CurrentPrice).value;
}
} else {
break;
}
}
There could be up to 120 hidden inputs on the form. The moment we check for an input that doesn't exist the loop should break. My test page has two input elements that get pulled. On the third (the null) I get this error in firebug:
prevDoc.getElementById(CurrentPrice) is null
if (prevDoc.getElementById(CurrentPrice).value != null) {
Yes it is null...that's what the check is for ?_?
Does any one know what I'm doing wrong? This seems like it should be really straight forward.
EDIT: for clarity's sake, prevDoc=window.opener.document
© Stack Overflow or respective owner