title: Select values retrieve
body: <p>Dear friends with this function I retrieve the values selected by my users and I put it in a hidden field to use it in my form:</p>
  
  <pre><code>    &lt;SCRIPT type="text/javascript"&gt;  function updateHidden(sel){   
  var f = document.contract;   
  f.sel_value.value = sel.options[sel.selectedIndex].value;
   } &lt;/SCRIPT&gt;
  </code></pre>
  
  <p>The problem is  that my select is inside a while cycle and therefore repeated. The js function set this way reads only the value selected in the first select.
  I need to add a loop in the function, but I don’t know where to put it. 
  This is my form:  </p>
  
  <pre><code>    &lt;form action="update.php" method="POST" name="contract"&gt;
   &lt;table class="myp-table"&gt;
   &lt;tr&gt;
   &lt;td class="head-act"&gt;Contract&lt;/td&gt;
   &lt;/tr&gt;
   &lt;?php do { ?&gt;
   &lt;tr&gt; 
   &lt;td class="head-act"&gt;&lt;select name="playerContract[]" onchange="updateHidden(this)"&gt;
   &lt;option value="0" &lt;?php if (!(strcmp(0, $row_datacontract['playerContract']))) {echo "selected=\"selected\"";} ?&gt;&gt;0&lt;/option&gt;
    &lt;option value="1" &lt;?php if (!(strcmp(1, $row_datacontract['playerContract']))) {echo "selected=\"selected\"";} ?&gt;&gt;1&lt;/option&gt;
    &lt;option value="2" &lt;?php if (!(strcmp(2, $row_datacontract['playerContract']))) {echo "selected=\"selected\"";} ?&gt;&gt;2&lt;/option&gt;
     &lt;option value="3" &lt;?php if (!(strcmp(3, $row_datacontract['playerContract']))) {echo "selected=\"selected\"";} ?&gt;&gt;3&lt;/option&gt;
   &lt;/select&gt;
  &lt;input type="hidden" name="sel_value"&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input name="id[]" type="hidden" value="&lt;?php echo $row_datacontract['id']; ?&gt;"/&gt; &lt;/td&gt;
   &lt;/tr&gt;
   &lt;?php } while ($row_datacontract = mysql_fetch_assoc($datacontract)); ?&gt;
   &lt;tr class="zebra"&gt;
   &lt;td&gt;&lt;input class="linkbuttonmp"  name="contract" id="submit" type="submit" value="Invio" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
   &lt;/table&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>Thank you.</p>