1 Replies - 1829 Views - Last Post: 20 September 2012 - 10:47 AM

#1 RyanRobinson  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 39
  • View blog
  • Posts: 227
  • Joined: 31-March 10

Object values not getting concatenated

Posted 19 September 2012 - 03:04 PM

Hi guys,

Is this me going mad or have I missed something stupid here?

Here is the code:

(function showErrors() {
	if((typeof errorObj) == 'object') {
		var alertStr = "Errors found: \n\n";
		for(prop in errorObj) {
			var element = document.getElementById(prop);
			element.style.border = '#FF0000 2px solid';
			//alert(errorObj[prop]);
			alertStr += errorObj[prop] + "\n"; 			
		}
		alert(alertStr);
	}else {
		alert('none');	
	}
})();



This function executes no problem as the border styling works as does the alert that is currently commented out. The thing that isn't working is the alert(alertStr) part of the code (line 10) at the end of the for in loop. My browser won't alert the string that has been built in the loop.

Any ideas?

EDIT: After some more playing around with it. It seems that any code after the for in loop does not execute, which is strange as I thought JS ran top to bottom?

This post has been edited by RyanRobinson: 19 September 2012 - 03:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Object values not getting concatenated

#2 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: Object values not getting concatenated

Posted 20 September 2012 - 10:47 AM

Where is 'errorObj' defined or set?

May not be that the 'for in ...' loop is incorrect,
but that there is no information in the errorObj element.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1