Can't get JavaScript to check for null objects -


i don't know issue here. far can see, code simple , should work fine.

          var prices="";           (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 120 hidden inputs on form. moment check input doesn't exist loop should break. test page has 2 input elements pulled. on third (the null) error in firebug:

prevdoc.getelementbyid(currentprice) null   if (prevdoc.getelementbyid(currentprice).value != null) { 

yes null...that's check ಠ_ಠ

does 1 know i'm doing wrong? seems should straight forward.

edit: clarity's sake, prevdoc=window.opener.document

if (prevdoc.getelementbyid(currentprice).value != null) { 

can expanded to:

var element = prevdoc.getelementbyid(currentprice);     var value = element.value; /* element null, you're accessing .value */  if (value != null) {  

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -