Posted on

Loop through form ids with different names in Javascript

<select name=”EiPromoPenny0″ id=”EiPromoPenny0″>
<option value=0>00</option>
<option value=99>99</option>
<option value=1 selected=”selected”>01</option>
<option value=2>02</option>
<option value=3>03</option>
</select>
<select name=”EiPromoPenny1″ id=”EiPromoPenny1″>
<option value=”red”>red</option>
<option value=”green” selected=”selected”>green</option>
<option value=”blue”>blue</option>
</select>
<select name=”EiPromoPenny2″ id=”EiPromoPenny2″>
<option value=”a”>a</option>
<option value=”b” selected=”selected”>b</option>
<option value=”c”>c</option>
</select>

<script language=”javascript” type=”text/javascript”>
for( var i = 0; i<=2; i++){
alert(document.getElementById(“EiPromoPenny” + i).value);
}
</script>