Problem: Alert value of dynamically created select tags
<p>I have an external Javascript file and i am trying to alert the value of select tags which are being generated dynamically through php.</p>

<p>the problem is, that it selectes the value of only the first select tag. What should i do, so that the javascript is able to independently identify each select tags value.  </p>

<p>My <code>&lt;select&gt;</code> code looks like this:</p>

<pre><code>&lt;select id="vote"&gt;
&lt;option value="1"&gt;1&lt;/option&gt;
&lt;option value="2"&gt;2&lt;/option&gt;
&lt;option value="3"&gt;3&lt;/option&gt;
&lt;option value="4"&gt;4&lt;/option&gt;
&lt;option value="5"&gt;5&lt;/option&gt;
&lt;/select&gt;&lt;input type="button" value="vote" onclick="castvote();"&gt;
</code></pre>

<p>and the Javascript (which is external):</p>

<pre><code>function castvote()
{    
var sel=document.getElementById("vote");
alert(sel.options[sel.selectedIndex].value);}
</code></pre>

<p>The javascript just alerts the value of first select tag. even if i change value of some other select tag and click on the corresponding button.</p>

<p>I hope i am able to explain my issue. 
Can someone help me with this. </p>

<p>Best Zeeshan</p>
