title: How to get button value using Javascript
body: <p>I am trying to figure out how to get the value of a button using JavaScript. There are several buttons generated using a while statement in php code, so the <code>name</code> and <code>id</code> are the same for all of them. The only difference between them is the value.</p>
  
  <p>Part of my php code:</p>
  
  <pre><code>while($row = mysql_fetch_array($result))
       {
       echo "&lt;tr&gt;";
       echo "&lt;td align=\"center\"&gt;&lt;input type=\"button\" id=\"details\" name=\"details\" value=\"" . $row['mcn'] . "\" onClick=\"MCNdetails()\"&gt;&lt;/td&gt;";
       echo "&lt;/tr&gt;";
       }
  </code></pre>
  
  <p>What I'm trying to achieve is that when this button is clicked a JavaScript alert is displayed with this records details.</p>
  
  <p>(FYI - "Faker" is the form name that this table is a part of.)</p>
  
  <p>My JavaScript code:</p>
  
  <pre><code>function MCNdetails()
          {
  
          var buttonDetails = document.Faker.details;
          var buttonValue = buttonDetails.value;
  
          if (buttonValue === "2700-2057" )
              {
              alert ("Details are here");
              return;
              }
          else
              {
              alert ("No Dice " + buttonValue);
              return;
              }
  
          }
  </code></pre>
  
  <p>I have approx. 300 records so far. When I click on ANY of the buttons I always get the else statement. I did try getting the element by id like this:</p>
  
  <pre><code>function MCNdetails()
          {
  
          var buttonDetails = document.getElementById("details");
          var buttonValue = buttonDetails.value;
  
          if (buttonValue === "2700-2057" )
              {
              alert ("Details are here");
              return;
              }
          else
              {
              alert ("No Dice " + buttonValue);
              return;
              }
  
          }
  </code></pre>
  
  <p>But that would always return the value of the first button regardless of which one I clicked.</p>
  
  <p>I have done some Google searching as well as searching this site and I can't find this same scenario where the buttons are generated.</p>
  
  <p>Any help or pointers would be appreciated. Thank you for your time :)</p>