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

Less lines...

Status
Not open for further replies.

Phil79

Technical User
Jun 5, 2002
64
GB
Hi guys.

I am using the code below, but i know that it is going about it in a very long winded manner. Basically, the below code is repeated six times. I've included it twice so that you can see what changes between the instances. Basically it refers to elements b1, fl1 and s1 in the first instance, b2, fl2 and s2 in the second etc. I really cant get this to work in a for loop. Could someone please put me out of my misery.

Code:
	// fl1
		fl1.style.display='none';
		document.main.b1.style.top=parseInt(document.main.s1.style.top);
		document.main.b1.style.left=parseInt(document.main.s1.style.left)+129;
		fl1.style.left=parseInt(document.main.s1.style.left)+2;
		fl1.style.top=parseInt(document.main.s1.style.top)+19
		document.main.b1.src="button1.gif";

	// fl2
		fl2.style.display='none';
		document.main.b2.style.top=parseInt(document.main.s2.style.top);
		document.main.b2.style.left=parseInt(document.main.s2.style.left)+129;
		fl2.style.left=parseInt(document.main.s2.style.left)+2;
		fl2.style.top=parseInt(document.main.s2.style.top)+19
		document.main.b2.src="button1.gif";
etc...

Thanks in advance,

Phil

PS: This is for intranet use and everyone is using IE5.5 or 6.
 
var num=6;
for (i=1; i<num+1;i++)
{
eval(&quot;fl&quot;+i+&quot;.style.display='none');
eval(&quot;document.main.b&quot;+i+&quot;.style.top=parseInt(document.main.s&quot;+i+&quot;.style.top)&quot;);
eval(&quot;document.main.b&quot;+i+&quot;.style.top=parseInt(document.main.s&quot;+i+&quot;.style.top)&quot;);
eval(&quot;document.main.b&quot;+i+&quot;.style.top=parseInt(document.main.s&quot;+i+&quot;.style.top)&quot;);
eval(&quot;document.main.b&quot;+i+&quot;.style.left=parseInt(document.main.s&quot;+i+&quot;.style.left)+129&quot;);
eval(&quot;fl&quot;+i+&quot;.style.left=parseInt(document.main.s&quot;+i+&quot;.style.left)+2&quot;);
eval(&quot;fl&quot;+i+&quot;.style.top=parseInt(document.main.s&quot;+i+&quot;.style.top)+19&quot;);
eval(&quot;document.main.b&quot;+i+&quot;.src='button1.gif'&quot;);
}
 
Or, using a subroutine --
Code:
// f11
  xSetParm(f11,document.main.b1,document.main.s1)
// f12
  xSetParm(f12,document.main.b1,document.main.s1)

function xSetParm(FKey,B1,S1) {
  FKey.style.display = 'none';
  B1.style.top       = parseInt(S1.style.top);
  B1.style.left      = parseInt(S1.style.left)+129;
  FKey.style.left    = parseInt(S1.style.left)+2;
  FKey.style.top     = parseInt(S1.style.top)+19
  B1.src             = &quot;button1.gif&quot;;
}
No loops may be the ticket when you're having trouble getting the loops to work.
 
Excellent. That's exactly what I needed. Thanks a lot guys.

Phil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top