我在同一页面上搜索

时间:2014-02-24 10:54:48

标签: javascript php

当我点击许可证的类别时,没有任何反应。

  <script>
function goToPage( select1 ) {

  var node = document.getElementById( select1 );

  if( node &&
    node.tagName == "SELECT" ) {

    // Go to web page defined by the VALUE attribute of the OPTION element

    window.location.href = node.options[node.selectedIndex].value;

  } // endif


}
</script>  
                   <center><label for="select1">Go to Marker</label></center>
                <select id="select1" onChange="goToPage('select1')">
                  <?php
                    $conn=mysql_connect("localhost","root","");
                    mysql_select_db("dbposo",$conn);

                    $news=mysql_query("select id,license from tblviolator");

                    while($data=mysql_fetch_array($news))
                        {
                            $id=$data['id'];
                            $license=$data['license'];

                            print "
                                <option value='#X$id'>$license</option>
                            ";
                        }
                    ?>  

                  </select>

1 个答案:

答案 0 :(得分:0)

您只需按如下方式编写您的选择标记,而无需调用该函数。如果您只想重定向选择框的值

<select id="select1" onChange="window.location.href=this.value;">

更新2:

<script>
var current_url = window.location.href ;
function goToPage(val) {

    window.location.href = current_url+val;
}
</script> 

<select id="select1" onChange="goToPage(this.value);">
相关问题