如何用javascript取多个同名下拉框的值
<form id= "form1 " name= "form1 " method= "post " action= " ">
<select name= "select " id= "select ">
<option value= "sdfsdf "> asdfsdf </option>
</select>
<select name= "select " id= "select ">
<option value= "sdfsdf "> asdfsdf </option>
</select>
<script language= "JavaScript " type= "text/javascript ">
if(select.value) {
在网页上显示 }
</script>
</form>
这样子不成功,请赐教啊
------解决方案-------------------- alert(select[0].value)
alert(select[1].value)
------解决方案--------------------可以用document.getElementsByName( 'xxx ')来获取这一组同名的元素,然后加下标引用,如:
<form id= "form1 " name= "form1 " method= "post " action= " ">
<select name= "select " id= "select ">
<option value= "aaaaa "> aaaaa </option>
</select>
<select name= "select " id= "select ">
<option value= "bbbbbb "> bbbbbb </option>
</select>
<script language= "JavaScript " type= "text/javascript ">
var obj=document.getElementsByName( 'select '); //取得所有name为select的元素
for(i=0;i <obj.length;i++)//遍历所有name为select的元素
alert(obj[i].value);
</script>
</form>
------解决方案--------------------楼上的正确