Javascript swapping values <p>I need to be able to go through a randomized 3 x 3 matrix and check to see if the numbers are in order (i.e. that the top row is 1-3, center 4-6 and bottom 7-9). So far i wrote this function in JS:</p> <pre><code>function winningorder(topleft, topcenter, topright, centerleft, centercenter, centerright, bottomleft, bottomcenter, bottomright){ if(document.getElementById(topleft).innerHTML = 1 &amp;&amp; document.getElementById(topcenter).innerHTML = 2 &amp;&amp; document.getElementById(topright).innerHTML = 3 &amp;&amp; document.getElementById(centerleft).innerHTML = 4 &amp;&amp; document.getElementById(centercenter).innerHTML = 5 &amp;&amp; document.getElementById(centerright).innerHTML = 6 &amp;&amp;document.getElementById(bottomleft).innerHTML = 7 &amp;&amp; document.getElementById(bottomcenter).innerHTML = 8 &amp;&amp; document.getElementById(bottomright).innerHTML = 9){ setTimeout(function(){ alert("Well Done!"); }, 250); } </code></pre> <p>I do not know if i need to put all the locations (the HTML id of each cell) as the parameters, so that is my first question. Secondly, where would i put my function in the HTML code. the code is:</p> <pre><code>&lt;table border=1&gt; &lt;tr class="numberrow"&gt; &lt;td id="topleft" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)" &gt;&lt;/td&gt; &lt;td id="topcenter" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;td id="topright" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="numberrow"&gt; &lt;td id="centerleft" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;td id="centercenter" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;td id="centerright" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr class="numberrow"&gt; &lt;td id="bottomleft" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;td id="bottomcenter" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;td id="bottomright" class="numbertile" onclick="processclick(this.id)" onchange=="winningorder(id)"&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p></p> <p>My first though was to use an onchange event and run the function but that is not working. Thanks for any help!</p>