title: How to add buttons in an array and loop through them?
body: <p>Got a bunch of letter buttons in code below:</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
      $a = range("A","Z");
  ?&gt;
  
  &lt;table id="answerSection"&gt;
      &lt;tr&gt;
  
  &lt;?php
      $i = 1;
      foreach($a as $key =&gt; $val){
          if($i%7 == 1) echo"&lt;tr&gt;&lt;td&gt;";
          echo"&lt;input type=\"button\" onclick=\"btnclick(this);\" value=\"$val\" id=\"answer".$val."\" name=\"answer".$val."Name\" class=\"answerBtns answers answerBtnsOff\"&gt;";      
          if($i%7 == 0) echo"&lt;/td&gt;&lt;/tr&gt;";
          $i++;
      }
  ?&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Now the code below is able to turn on an answer button:</p>
  
  <p>Code:</p>
  
  <pre><code>function addwindow(btn) { 
  $('#answer'+btn).addClass("answerBtnsOn");
  }
  </code></pre>
  
  <p>But the only problem is that the code above is only able to turn on a single answer button on only. For example if the "Answer" is <code>B</code>, then it will look for button <code>"#answerB"</code> and turn on that button which is button <code>B</code>. or if the "Answer" is <code>E</code>, then it will look for button <code>"#answerE"</code> and turn on that button which is button <code>E</code>.</p>
  
  <p>The problem is that if there are multiple answers. If the "Answer" is <code>B E,</code> then it does not turn on buttons <code>B</code> and <code>E</code>. This is because it is trying to find button <code>"#answerBE"</code> which is incorrect, it should be looking for button <code>"#answerB"</code> and button <code>"#answerE"</code> and turn them both on. </p>
  
  <p>Another example is if "Answer" is <code>A D F,</code> it doesn't turn on buttons <code>A</code> <code>D</code> and <code>F</code> because it is trying to find button <code>"#answerADF"</code> which is incorrect, it should be looking for button <code>"#answerA"</code>, button <code>"#answerD"</code>, and button <code>"#answerF"</code> and turn them all on. </p>
  
  <p>So my question is that how can I turn on multiple buttons if there are multiple Answers? Do I need to put all the buttons in an array and loop through them so that it is able to go through all the buttons and turn on those buttons which should be turn on?</p>
  
  <p>UPDATE:</p>
  
  <p>Below is the "Add" button which calls on the addwindow() function and above the add button is the "Answer" column where it displays rows of Answers</p>
  
  <pre><code>   echo '&lt;td class="noofanswerstd"&gt;'.htmlspecialchars($searchNoofAnswers[$key]).'&lt;/td&gt;';
      echo "&lt;td class='addtd'&gt;&lt;button type='button' class='add' onclick=\"parent.addwindow('$searchAnswer[$key]');\"&gt;Add&lt;/button&gt;&lt;/td&gt;&lt;/tr&gt;";
  </code></pre>