<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1016498" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1016498</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/functions-arrays-and-loops-oh-my#comment-1095918</link>
    <description> &lt;p&gt;Hi htmler,&lt;/p&gt;
&lt;p&gt;Re:&lt;br /&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;Quote: Your advice was fantastic.&lt;/blockquote&gt;&lt;/p&gt;
&lt;p&gt;Easy on the accolades; they&#039;ll go to my head. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/big.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; class=&quot;smiley-content&quot; /&gt;&lt;br /&gt;
If you found the above helpful, check out my site -- there may be things there you&#039;d find equally helpful.&lt;/p&gt;
&lt;p&gt;BTW: do you have a url where you are using this?  I am slightly curious as to why an individual would have to click on all divs.&lt;/p&gt;
&lt;p&gt;Vinny&lt;/p&gt;
 </description>
     <pubDate>Tue, 11 Dec 2001 00:39:57 +0000</pubDate>
 <dc:creator>Vincent Puglia</dc:creator>
 <guid isPermaLink="false">comment 1095918 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title>thanks!!</title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/functions-arrays-and-loops-oh-my#comment-1095913</link>
    <description> &lt;p&gt;Vinny~&lt;/p&gt;
&lt;p&gt;Your advice was fantastic.  Thanks for taking the extra time to walk me through my code and even suggest alternatives.  It makes learning much easier.  The code worked fine, too.  Learning javascript can be frustrating but replies such as yours are encouraging and very helpful.  Besides books and websites, this is my only other resource for learning or seeking help, and I appreciate the time that you spent.&lt;/p&gt;
&lt;p&gt;Danka&lt;/p&gt;
 </description>
     <pubDate>Mon, 10 Dec 2001 23:15:19 +0000</pubDate>
 <dc:creator>htmler</dc:creator>
 <guid isPermaLink="false">comment 1095913 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/html-css-and-javascript/functions-arrays-and-loops-oh-my#comment-1095808</link>
    <description> &lt;p&gt;Hi htmler,&lt;/p&gt;
&lt;p&gt;Your major problem is:&lt;/p&gt;
&lt;p&gt;assignment versus comparison&lt;/p&gt;
&lt;p&gt;Javascript (and other C-like languages) use the following conventions:&lt;/p&gt;
&lt;p&gt;assignment -- &quot;=&quot; (one equal sign)&lt;br /&gt;
  var x = 2;&lt;br /&gt;
comparison -- &quot;==&quot; (two equal signs)&lt;br /&gt;
  if (x == 2) doSomething();&lt;/p&gt;
&lt;p&gt;Second major problem:&lt;br /&gt;
using a variable without declaring it -- &#039;layer&#039;&lt;br /&gt;
Because a div exists, doesn&#039;t mean the var &#039;layer&#039; is known to a function.  For that to happen, you must pass the div to the function --&lt;/p&gt;
&lt;p&gt;&#039;this&#039; is a javascript keyword that points to whatever is being referenced, so in the first case, &#039;this&#039; means the div that has &#039;answer1&#039; as an id; in the second, it refers to the div that has &#039;answer2&#039; as the id.&lt;/p&gt;
&lt;p&gt;once you pass the div object (with the &#039;this&#039; keyword), you need to have the function recognize it --&lt;/p&gt;
&lt;p&gt;      function layerSelected(layer)&lt;/p&gt;
&lt;p&gt;now &#039;layer&#039; is a declared &amp;amp; defined variable, so the browser can now interpret the following line:&lt;/p&gt;
&lt;p&gt;   if (layer.id == &#039;answer1&#039;) setLayer[0] = 1 &lt;/p&gt;
&lt;p&gt;btw: you can also rewrite the above lines by sending the id directly as in:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;div id=&amp;quot;answer1&amp;quot; onClick=&amp;quot;layerSelected(this.id)&amp;quot;&amp;gt;&amp;lt;/div&amp;gt; &lt;br /&gt;function layerSelected(layerID)&lt;br /&gt;if (layerId == &amp;#039;answer1&amp;#039;) setLayer[0] = 1 &lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;Next, if you want to redirect &#039;only if&#039; all layers have been clicked, you need to set a boolean variable and check it before redirecting (see function below)&lt;/p&gt;
&lt;p&gt; if (isGood)   window.location=&quot;next_page.htm&quot; &lt;/p&gt;
&lt;p&gt;Finally, you could have written this line -- &lt;/p&gt;
&lt;p&gt;var setLayer = new Array(2) &lt;/p&gt;
&lt;p&gt;as any of the following:&lt;/p&gt;
&lt;p&gt;1) state 3 cells will be created; then fill them as you did (setLayer[0] = 0;....etc)&lt;/p&gt;
&lt;p&gt;var setLayer = new Array(3); &lt;/p&gt;
&lt;p&gt;2)leave the number of cells unknown; then fill them as you did (setLayer[0] = 0;....etc)&lt;/p&gt;
&lt;p&gt;var setLayer = new Array();&lt;/p&gt;
&lt;p&gt;3) declare &amp;amp; assign the array in one statement (no need to fill cells)&lt;/p&gt;
&lt;p&gt;var setLayer = new Array(0,0,0);&lt;/p&gt;
&lt;p&gt;Here&#039;s the completed code:&lt;br /&gt;
&amp;lt;script language=&#039;javascript&#039;&amp;gt;&lt;br /&gt;
var setLayer = new Array(0,0,0);&lt;/p&gt;
&lt;p&gt;function layerSelected(divID)&lt;br /&gt;
{&lt;br /&gt;
  if (divID == &#039;answer1&#039;) setLayer[0] = 1&lt;br /&gt;
  else if (divID == &#039;answer2&#039;) setLayer[1] = 1&lt;br /&gt;
  else if (divID == &#039;answer3&#039;) setLayer[2] = 1&lt;br /&gt;
} &lt;/p&gt;
&lt;p&gt;function checkLayers()&lt;br /&gt;
{&lt;br /&gt;
   var isGood = true;&lt;br /&gt;
   for (var i = 0; i &amp;lt;= setLayer.length; i++)&lt;br /&gt;
   { &lt;/p&gt;
&lt;p&gt;      if (setLayer[i] == 0)&lt;br /&gt;
      {&lt;br /&gt;
         isGood = false;&lt;br /&gt;
         alert (&quot;Where else could you find this information?&quot;);&lt;br /&gt;
         break;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   if (isGood)   window.location=&quot;next_page.htm&quot;&lt;br /&gt;
} &lt;/p&gt;
&lt;p&gt;Hope this explains your initial problems.  You will probably have additional problems, dependent upon the specific browsers and code you use.&lt;/p&gt;
&lt;p&gt;Vinny&lt;/p&gt;
 </description>
     <pubDate>Sun, 09 Dec 2001 17:54:11 +0000</pubDate>
 <dc:creator>Vincent Puglia</dc:creator>
 <guid isPermaLink="false">comment 1095808 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
