Current location: Hot Scripts Forums » General Web Coding » JavaScript » null or not an object


null or not an object

Reply
  #1 (permalink)  
Old 10-27-04, 05:25 AM
ccgorman ccgorman is offline
New Member
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
null or not an object

I am getting the error message:

'document.all[...].style' is null or not an object, and I want to get rid of this. I was hoping that there was a test if a variable or object exists before a command runs.

The problem is happening at this line document.all[devtext].style.color=text;

I tried to put in an if statement, but that just causes the error at the if statement, so I need something to test if an object exists prior to calling it.

Here is the code where the problem happens.

Code:
function highlightit(who,tf,bgcolor) {
	var dev='dev'+who;
	var devtext='devtext'+who;
	var highlight='#'+bgcolor;
	var border='#FFFFFF';
	var text='#FFFFFF';
	if (!tf) {
		highlight='#666666'
		border='#333333';
		text='#B2B2B2';
	}
	if (document.all) {
		document.all[dev].style.backgroundColor=highlight;
		document.all[dev].style.borderColor=border;
		if (document.all[devtext].style.color) {
			document.all[devtext].style.color=text;
		}
	}
	else if (document.layers){
		var layer = findLayer(dev,document);
		layer.bgColor=highlight;
		layer.borderColor=border;
		layer = findLayer(devtext,document);
		if (layer.color) {
			layer.color=text;
		}
	}	
	else if (document.getElementById) {
		document.getElementById(dev).style.backgroundColor=highlight;
		document.getElementById(dev).style.borderColor=border;
		if (document.getElementById(devtext).style.color) {
			document.getElementById(devtext).style.color=text;
		}
	}
}
Reply With Quote
  #2 (permalink)  
Old 10-27-04, 06:41 AM
ccgorman ccgorman is offline
New Member
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sorted it, named the div tag wrong.
Reply With Quote
  #3 (permalink)  
Old 10-27-04, 06:59 AM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
perhaps you named the DIV tag wrong.




(I'm just kidding.) Good work.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login script cyberted Script Requests 2 05-06-04 01:57 AM
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
Help with making a installer config script dazz Job Offers & Assistance 3 09-29-03 02:51 AM


All times are GMT -5. The time now is 10:32 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.