当我点击选择表格时,不要显示数据=" id = undefined"

时间:2016-05-01 20:43:40

标签: javascript php html

请帮帮我..它显示" select_modelcar.php?brandid=undefined"当我选择选择表单但我尝试将此代码粘贴到网址并定义ID​​" select_modelcar.php?brandid=40"时,会得到结果。我想在选择的形式中选择相同的类别,例如当我选择品牌"丰田"时,它会显示丰田品牌的所有车型(凯美瑞,雅力士等)。

当我点击选择表格>>

enter image description here

过去在网址中并定义ID​​>>

enter image description here

select_brandcar.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
</head>

<?php $servername = "localhost";
$username = "root";
$password = "usbw";
mysql_connect($servername,$username,$password);
mysql_select_db("carspecth");
 ?>
 
<body>

<script>
 function ValueID(){
     document.getElementById("getval").innerHTML = ('select_modelcar.php?brandid='+this.value);;
 };
</script>

    <select name="select_brandcar" id="select_brandcar" onclick="ValueID();" >
    <option>Press Choose</option>
    <?php 
  	$sql = sprintf ("SELECT * FROM brand" );
   	$res = mysql_query ($sql);
  	while ($arr = mysql_fetch_array($res)){
	printf ("<option value='%s'>%s</option>" ,$arr['brandid'], $arr['brandname']);
	}
   ?>
<span id="getval"></span>

</body>
</html>
&#13;
&#13;
&#13;

select_modelcar.php

<?php
mysql_query("SET NAMES UTF8");
include 'include_connectdb.php';
@$varbrandid = $_GET['brandid'];
@$sql = sprintf("SELECT * FROM maingeneration WHERE brandfk = %s", $varbrandid);
/*id ของตาราง catagory*/
@$res = mysql_query($sql);
printf("<select name='select' id='select'>");
while ($arr = mysql_fetch_array($res)) {
    printf("<option value='%s'>%s</option>", $arr['maingenerationid'], $arr['maingenerationname']);
}
printf("</select>");
?>

1 个答案:

答案 0 :(得分:0)

以下是一些建议:

onclick替换为onchange

传递select的值,如下所示:onchange='ValueID(this.value);' 然后更改函数以获取该值:

function ValueID(brandid){
     document.getElementById("getval").innerHTML = ('select_modelcar.php?brandid='+brandid);;
 };