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!

modify script 2

Status
Not open for further replies.

coderwasp

Programmer
Jan 10, 2007
24
US
I have a script that toggles on and off the visibility of table rows. This works good except I need a script that simply turns off the visibility and does not toggle it.

Code:
function toggleoff(obj) {
var aTR=obj.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('tr');
var show=(document.all)? 'block' : 'table-row';
for(var i=5; i<11; i++) {
aTR[i].style.display=(aTR[i].style.display=='none')? show : 'none';
}
}
 
This line is what toggle it:

Code:
aTR[i].style.display=(aTR[i].style.display=='none')? show : 'none';

it says if not currently shown, then show, else it must currently be show, so don't show.

Since I told you the line, see if you can fix this yourself. [yoda]

[monkey][snake] <.
 
I don't understand the logic behind it. It' not as if you have conditionals in it.

I've figured out that if I do this: aTR.style.display=(aTR.style.display=='inline')? show : 'inline';

it will always show.

I need the exact opposite.
 
The if... else is most certainly in that example. Do a search for ternary operator to find out more about it.

Lee
 
thanks for that tip. The end resut is:

aTR.style.display=(aTR.style.display=='none')? 'none' : 'none';
 
You can optimize that, you are making that WAY harder than it has to be.

If you just look at the code then understand it, you'll see what I mean.

[monkey][snake] <.
 
I'll write you out some psuedocode:

aTR.style.display=(aTR.style.display=='none')? 'none' : 'none';

means

I'm going to set the display value of the object aTR equal to a value. That value will be set to 'none' if the current display value of aTR is already 'none'. If the current display value of aTR is NOT already 'none', then I'll set the display value to 'none'.


Why not just say:

I'm going to set the display value of the object aTR equal to a value. I will make that value 'none'.



[monkey][snake] <.
 
how can I modify this function to pass it a specific value or a specific set of values?

for example right now I am invoking it like this:

onClick="toggleprob(this);"

I'd likre to do it like this onClick="toggleprob(3,4);"

and have table rows in position 3 become visible and table rows in position 4 become invisible.

Or better yet if I assign an id to the tr, can I just pass the specific id's to the function?

 
Or better yet if I assign an id to the tr, can I just pass the specific id's to the function?

You can do that, that's how I'd go about it if I need to specify an object.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top