<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
  function getOptionPage(){
 var optionResult=document.getElementsByName("sno");
 var optionValue=optionResult[optionResult.selectedindex].value;
 window.location.href="getSelectValue.jsp?page="+optionValue;
 }
  
</script><title>无标题文档</title>
</head><body>
<select name="sno" onclick="getOptionPage()">选择
    <option value="1" >1</option>
    <option value="2">2</option>
    <option value="3">3</option>
  </select>
</body>
</html>这儿当选中一个时,在js中获取选中的值,把该值传给另一个jsp页面,在另一个jsp页面获取。
这儿为什么无法获取选择的值??有什么语法错误??

解决方案 »

  1.   

    var optionValue=optionResult[0].options[optionResult[0].selectedindex].value;你获取的optionRestult是一个数组对象
      

  2.   

    错误一、var optionResult=document.getElementsByName("sno");//获取的是一组对像所,还有select取值不对
    var optionValue=optionResult[0].options[optionResult[0].options.selectedIndex].value;
    错误二、select用onclick事件(可怕)没选择的余地
    下面已经解决了以上两个问题。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
    <title>js获取下拉列表框值问题</title><script>
    function getOptionPage(){
    var optionResult=document.getElementsByName("sno");
    var optionValue=optionResult[0].options[optionResult[0].options.selectedIndex].value;
    window.location.href="getSelectValue.jsp?page="+optionValue;
    }
    </script>
    </head>
    <body>
    选择<select name="sno" onchange="getOptionPage()"><option value="1" >1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      </select>
    </body>
    </html>
      

  3.   

    $("select[name='sno']").change(function(){
    alert($(this).val());
    });
      

  4.   

    用select控件的ID吧:
    <select id="sno" ...</select>获取选中的值:
    var optionValue=document.getElementById("sno").value;
    window.location.href="getSelectValue.jsp?page="+optionValue;