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

Comment this javascript!!!!

Status
Not open for further replies.

leo2180

IS-IT--Management
Jun 7, 2000
52
US
Can someone please comment this javascript code for me, so that I could konw what exactly each line does...?<br><br><br>n = (document.layers) ? 1:0<br>ie = (document.all) ? 1:0<br>function show() {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (n) document.layer1.visibility = &quot;show&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (ie) layer1.style.visibility = &quot;visible&quot;<br>}<br>function hide() {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (n) document.layer1.visibility = &quot;hide&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (ie) layer1.style.visibility = &quot;hidden&quot;<br>}<br><br>&lt;/SCRIPT&gt;<br>
 
um, it shows and hides visibilities for either IE or netscape, seemed kind of obvious to me just by glancing at the code. I dont know what the &quot;? 1:0&quot; is, but the other thing is the objects to reach all the layers, in netscaoe you use document, layer, IE you have to grab all it seems.<br><br>are you familiar with the DOM (Document Object model) which allows you to try everything on the website as a object? <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
No I'm not familiar with it.&nbsp;&nbsp;It is obvious I know that, but I wasnt sure what the ? 1:0 was for, and thats what I wanted to know really.<br><br>
 
n = (document.layers) ? 1:0<br>//if document.layers = true, then n=1, otherwise n=0.<br>// this is a test to see if the browser is Netscape<br><br>ie = (document.all) ? 1:0<br>//if document.all = true, then ie=1, otherwise ie=0.<br>// this is a test to see if the browser is IE<br><br><br>//these two functions show and hide visibility for a layer, using each browsers specific implementation of CSS<br><br>function show() {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (n) document.layer1.visibility = &quot;show&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (ie) layer1.style.visibility = &quot;visible&quot;<br>}<br>function hide() {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (n) document.layer1.visibility = &quot;hide&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (ie) layer1.style.visibility = &quot;hidden&quot;<br>}<br><br> <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
&quot;Conditional if expression&quot;<br><br>C/C++, Java and Javascript syntax&nbsp;&nbsp;example:<br>&lt;1&gt; ? &lt;2&gt; : &lt;3&gt;;<br><br>if expression &lt;1&gt; evaluates to true then the entire expression evaluates to &lt;2&gt; otherwise the entire expression evaluates to &lt;3&gt;<br><br>It is supported in many languages although the syntax does vary. Parentheses are added as needed or for clarity.<br><br>-pete
 
if pete didn't get the point across, <br><br>in javascript:<br><br>true is the same thing as 1<br>and false is the same thing as 0, null <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
and 2 more to add to it <br><br>IE5 = (IE4 && navigator.appVersion.indexOf(&quot;5.&quot;)!=-1);<br>isMac = (navigator.appVersion.indexOf(&quot;Mac&quot;) != -1);<br><br>:)&nbsp;&nbsp;
 
I just use the 'true' and 'false' keywords, i.e.:<br><br>var cplusplusrules = true;<br><br>if ( java &gt; cplusplus)<br>&nbsp;&nbsp;cplusplusrules = false;<br><br>if ( cplusplusrules)<br>&nbsp;&nbsp;alert(&quot;That is absolutely correct!&quot;);<br>else<br>&nbsp;&nbsp;alert(&quot;Earth to user! Hello... anybody home?&quot;);<br><br>;o) Sorry... couldn't help myself<br>-pete
 
I'll second palbano- the whole &quot;1 is true, 0 is false&quot; thing is really weak. The code could be dramatically simplified like this:<br><br>function show() {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (document.layers) document.layer1.visibility = &quot;show&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (document.all) layer1.style.visibility = &quot;visible&quot;<br>}<br>function hide() {<br>&nbsp;&nbsp;&nbsp;&nbsp;if (document.layers) document.layer1.visibility = &quot;hide&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (document.all) layer1.style.visibility = &quot;hidden&quot;<br>}<br><br>And by the way... as Netscape 6 doesn't use layers (layers are only made use of in NN4), the boolean (integer???) variable &quot;n&quot; is not applicable, and so making the code seem easier to read does not really do so. I'd probably add comments to the stuff above in the sense that I'd want to explain what document.all and document.layers were... but it's usually a good idea to get rid of int/boolean. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top