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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Required error

Status
Not open for further replies.

abovetopsecret

Programmer
Jan 16, 2008
61
0
0
GB
I have an object required error and its coming from the bunch of code below, but cant work it out.

Code:
var step = 2; function objWidth(obj) {if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;} function objHeight(obj) {if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;} function scrF(i,sH,eH){var x=parseInt(i.top)+(dR? step: -step); if(dR && x>sH)x=-eH;else if(x<2-eH)x=sH;i.top = x+'px';} function startScroll(sN,txt){var scr=document.getElementById(sN); var sW = objWidth(scr)-6; var sH = objHeight(scr); scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; var sTxt=document.getElementById(sN+'in'); var eH=objHeight(sTxt); sTxt.style.top=(dR? -eH : sH)+'px'; sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; setInterval(function() {scrF(sTxt.style,sH,eH);},1000/speed);}
 
If you split it out on more than one line, then the line number in the error might mean something.

Code:
var step = 2;

function objWidth(obj) {
  if(obj.offsetWidth)
    return obj.offsetWidth;

  if (obj.clip)
    return obj.clip.width;
 
  return 0;
}

function objHeight(obj) {
  if(obj.offsetHeight)
    return obj.offsetHeight;

  if (obj.clip)
    return obj.clip.height;

  return 0;
}

function scrF(i,sH,eH){
  var x=parseInt(i.top)+(dR? step: -step);

  if(dR && x>sH)
    x=-eH;
  else if(x<2-eH)
    x=sH;

  i.top = x+'px';
}

function startScroll(sN,txt){
  var scr=document.getElementById(sN);
  var sW = objWidth(scr)-6;
  var sH = objHeight(scr);
  scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>';
  var sTxt=document.getElementById(sN+'in');
  var eH=objHeight(sTxt);
  sTxt.style.top=(dR? -eH : sH)+'px';
  sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)';
  setInterval(function() {scrF(sTxt.style,sH,eH);},1000/speed);
}

Adam
 
Hi there,

Thanks for the advice and I went ahead and pasted the code as above, and the error dissapeared but the ticker no longer worked.

So I guess that it basically either needs to be in that block or I need to look at somethign else.

Shame though, I though we could have moved on with your suggestion.

Cheers
 
Ok I broke it up a little as below, and the error is more specific now.
Code:
var step = 2; 
function objWidth(obj) {if(obj.offsetWidth) return obj.offsetWidth; 
if (obj.clip) return obj.clip.width; 
return 0;
} function objHeight(obj) {if(obj.offsetHeight) return obj.offsetHeight; 
if (obj.clip) return obj.clip.height; 
return 0;
} function scrF(i,sH,eH){var x=parseInt(i.top)+(dR? step: -step); 
if(dR && x>sH)x=-eH;
else if(x<2-eH)x=sH;i.top = x+'px';
} function startScroll(sN,txt){var scr=document.getElementById(sN); 
var sW = objWidth(scr)-6; 
var sH = objHeight(scr); 
scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; 
var sTxt=document.getElementById(sN+'in'); 
var eH=objHeight(sTxt); 
sTxt.style.top=(dR? -eH : sH)+'px'; 
sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; 
setInterval(function() {scrF(sTxt.style,sH,eH);
},1000/speed);
}window.onload = addScrollers;

Its saying the error is on line 3 of the above code which is:

Code:
if (obj.clip) return obj.clip.width;
 
[1] In the global variable declaration part, besides having step declared and initialized, I suppose you have somewhere dR and speed the same. But, most importantly, you have three more variables to be declared.
[tt]
var step=2;
var dR=true; //or false, somewhere already
var speed=1; //or some integer, somewhere already
[blue]var sH, eH, sTxt; //must have these declared globally[/blue]
[/tt]
[2] In the initating function startScroll(), you have to stop them being declared as local.
[tt]
function startScroll(sN,txt){
var scr=document.getElementById(sN);
var sW = objWidth(scr)-6;
[red]//[/red]var sH = objHeight(scr);
[blue]sH = objHeight(scr);[/blue]
scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>';
[red]//[/red]var sTxt=document.getElementById(sN+'in');
[blue]sTxt=document.getElementById(sN+'in');[/blue]
[red]//[/red]var eH=objHeight(sTxt);
[blue]eH=objHeight(sTxt);[/blue]
sTxt.style.top=(dR? -eH : sH)+'px';
sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)';
setInterval(function() {scrF(sTxt.style,sH,eH);},1000/speed);
}
[/tt]
[3] Frequent variable and argument name collisions just create some confusion, but should resolve no problem.
 
ok sorry to keep posting guys, but im sort of managing to make the error more specific now.

Code:
var step=2; 
function objWidth(obj) {
	if (obj.offsetWidth) 
	[b]return obj.offsetWidth;[/b] 
	if (obj.clip) 
	return obj.clip.width; 
	return 0;
} 
function objHeight(obj) {
	if (obj.offsetHeight) 
	return obj.offsetHeight; 
	if (obj.clip) 
	return obj.clip.height; 
	return 0;
} 
function scrF(i,sH,eH){var x=parseInt(i.top)+(dR? step: -step); 
if(dR && x>sH)x=-eH;
else if(x<2-eH)x=sH;i.top = x+'px';
} function startScroll(sN,txt){var scr=document.getElementById(sN); 
var sW = objWidth(scr)-6; 
var sH = objHeight(scr); 
scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; 
var sTxt=document.getElementById(sN+'in'); 
var eH=objHeight(sTxt); 
sTxt.style.top=(dR? -eH : sH)+'px'; 
sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; 
setInterval(function() {scrF(sTxt.style,sH,eH);
},1000/speed);
}window.onload = addScrollers;

Its on this line now that is saing Object Required
Code:
[b]return obj.offsetWidth;[/b]

which is line 4. I havent a clue to be honest, maybe I need to declare something is it?

thanks again
 
Hi tsuji,

thanks for your help, I have done those changes as shown in the code below:
Code:
var speed=20; // scroll speed (bigger = faster)
var dR=false; // reverse direction
var sH; 
var eH;
var sTxt;

var step=2; 
function objWidth(obj) {
	if (obj.offsetWidth) 
	return obj.offsetWidth; 
	if (obj.clip) 
	return obj.clip.width; 
	return 0;
} 
function objHeight(obj) {
	if (obj.offsetHeight) 
	return obj.offsetHeight; 
	if (obj.clip) 
	return obj.clip.height; 
	return 0;
} 
function scrF(i,sH,eH){var x=parseInt(i.top)+(dR? step: -step); 
if(dR && x>sH)x=-eH;
else if(x<2-eH)x=sH;i.top = x+'px';
} function startScroll(sN,txt){
	var scr=document.getElementById(sN); 
	var sW = objWidth(scr)-6; 
	sH = objHeight(scr); 
scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; 
sTxt=document.getElementById(sN+'in'); 
eH=objHeight(sTxt); 
sTxt.style.top=(dR? -eH : sH)+'px'; 
sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; 
setInterval(function() {scrF(sTxt.style,sH,eH);
},1000/speed);
}window.onload = addScrollers;

BUT!

Im still getting the same error on the same line.
which is:

Code:
[b]return obj.offsetWidth;[/b]
 
Why do you still format the script preferring obscurity than clarity? You can do so, making it obscur, once you fully debug it.

startScroll() has to be called somewhere not shown. Hence, under var src line, make an alert see what you actually get.
[tt]
function startScroll(sN,txt){
var scr=document.getElementById(sN);
alert(scr.innerHTML); //temporary for debugging
//etc etc
}
[/tt]
Do you get what you expect in the alert?
 
Hi tsuji,

I do not code in honesty in JScript, this is a vertical scroller that I'm trying to debug to put in a site. I put that alert is and I got a <p></p> which i sorted out, and then on refresh i got nothing, but the object required error.

Im sorry that Im not working with you properly, just I'mnot sure what your on about and you are a lot more knowing of jscript than me, and in honesty Im struggling to comprehend your last post.

cheera again
 
here is the rest of it.

Code:
function addScrollers() {
// code each scroller as follows:
// startScroll('id of scroller div','content of scroller');
startScroll('myscroller','<p><a href="#"><u>MILLING MACHINES</u><\/a><\/p><p><a href="#">AJAX VMC 1000<\/a> - Fitted with Heidenhain 426 Control with fully interfaced 4th Axis...<\/p><p><a href="http:\/\/[URL unfurl="true"]www.felgall.com\/">YANG[/URL] VMC 1000<\/a> - Fitted with Fanuc OM-D Control...</p><p><a href="http:\/\/about.com\/">AJAX PREMIER 1500<\/a> - 3 Axis Turret Mill fitted with Anilam 1100 CNC Control...<\/p><p><a href="#">XYZ PRO3000<\/a> - Turret Mill with Proto Track CNC system (2 Off)...<\/p><p><a href="#">GATE PBM<\/a> - 2VS-L Manual Mill fitted with DRO...<\/p><p><a href="#">GATE PBM<\/a> - 2VS-L Manual Mill fitted with DRO...<\/p><p>&nbsp;</p><p><a href="#"><u>LATHES</u><\/a><\/p><p><a href="#">TAKISAWA CNC<\/a> - Lathe fitted with Fanuc Series 21IT Control...<\/p><p><a href="#">AJAX PREMIER 225<\/a> - x 1650 Gap Bed CNC Lathe, fitted with Fagor 800T Control...<\/p><p><a href="#">XYZ 1600<\/a> - Gap Bed Lathe...<\/p><p><a href="#">VIKING VT510<\/a> - Gap Bed Lathe...<\/p><p>&nbsp;</p><p><a href="#"><u>CO-ORDINATE MEASURING MACHINE</u><\/a><\/p><p><a href="#">Ferranti Merlin 750<\/a> - with the latest Aberlink 3D Software...<\/p><p>&nbsp;</p><p><a href="#"><u>SURFACE GRINDERS</u><\/a><\/p><p><a href="#">JONES AND SHIPMAN 5 4 0<\/a> - more...<\/p><p><a href="#">BARON – MAX<\/a> - with Auto Cross and Up Feeds...<\/p><p>&nbsp;</p><p><a href="#"><u>UNIVERSAL GRINDER</u><\/a><\/p><p><a href="#">JONES AND SHIPMAN 1 3 0 0<\/a> - more...<\/p>');startScroll('twoscroll','');
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top