title: Javascript: How to swap value of two images?
body: <p>Ok so I have a JavaScript function that swaps the <code>src</code> of two images which swaps the images themselves no problem.  However, I have two values that need switched along with the images themselves so I can later add the values up correctly. An example being,</p>
  
  <pre><code>img src="ble.jpg" id="F" value="" onclick="swap(5)"
  
  img src="ilk.jpg" id="4" value="2" onclick="swap(6)"
  </code></pre>
  
  <p>So, I want to swap the above values as well so that the first image obtains a value of "2" and the second a value of "".  Is there a way to do this?  I have been trying to figure out a way for days and it just isn't clicking.</p>
  
  <p>Here is the function to swap images:</p>
  
  <pre><code>var toggle=0;
  var saveNum;
  var pic="0";
  
  function swap (elem)
  {
     if (toggle == 0)
     {
          saveNum = elem;
          pic = document.images[parseInt(elem)].src;
          toggle++;
     }
     else 
     {
          hold = document.images[parseInt(elem)].src;
          document.images[parseInt(elem)].src = pic;
          document.images[parseInt(saveNum)].src = hold;
  
          toggle = 0;
     }
  
  }
  </code></pre>