Closed Thread Icon

Topic awaiting preservation: variables and such (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=7966" title="Pages that link to Topic awaiting preservation: variables and such (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: variables and such <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 12-05-2001 04:02

I have a function:
function change_close(object) {
object.style.display = "none";
}

That I use via
onClick change_close(content_5);

This works fine. But - let's say that I want to have several things happen, like setting the style.display for content_5, and control_5, as well as swapping an image ("button_5").

So I thought I would use something like
onClick=change_close(5);
but I can't figure out how to grab that and build the other names, so that I can perform the tasks. Like, with that object ("5"), how do I come up with
content_5.style.display="none";
control_5.style.display="none";
button_5.src = "closed.gif";

How do i assemble the full object name?



[This message has been edited by Pugzly (edited 12-05-2001).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 12-05-2001 04:33

This is one of those situations where an eval may be the way to go

function doSomething(num) {

eval('content_' +num+ '.style.display="none"');

}

you could also use an array in this situation






:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 12-05-2001 05:43

I agree.

The only objection that I've heard to using eval is that it is slower. This is true but for "onesie twosie" operations I would think the speed difference is negligible.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-05-2001 07:17

You can use something like this:

function change_close(index) {
&nbsp;&nbsp;&nbsp;&nbsp;document.all["content_" + index].style.display = "none";
&nbsp;&nbsp;&nbsp;&nbsp;document.all["control_" + index].style.display = "none";
&nbsp;&nbsp;&nbsp;&nbsp;// you can also use my getObj() function above, like this
&nbsp;&nbsp;&nbsp;&nbsp;// getObj("content_"+index).style.display = "none";
&nbsp;&nbsp;&nbsp;&nbsp;// getObj("control_"+index).style.display = "none";
&nbsp;&nbsp;&nbsp;&nbsp;document.images["button_" + index].src;
}


Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 12-05-2001 17:19

Cool....The eval thing works great. I'll try using the GetObject idea as well. It's basically just a concept I'm working on with collapsible DIVs such as shown here. I have the two parts of the div - the content part ("content_"), and the titlebar part ("control_"). I also have a little restore button that swaps out the maximize button when the control div is maximized.

Thanks for the help. I'm learning!

« BackwardsOnwards »

Show Forum Drop Down Menu