点击select form =“id = undefined”

时间:2016-05-05 07:47:29

标签: php ajax

请帮帮我..它显示" 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>");
?>

谢谢...........!

2 个答案:

答案 0 :(得分:2)

$(document).ready(function(){
  var a ="test" ;

    $('a').each(function(){
        this.href = this.href.replace('ONE', 'ONE-'+a);
    });
});

答案 1 :(得分:0)

试试这个:

<!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(element){
     document.getElementById("getval").innerHTML = ('select_modelcar.php?brandid='+element.value);;
 };
</script>

    <select name="select_brandcar" id="select_brandcar" onclick="ValueID(this);" >
    <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']);
	}
   ?>
</select>
<span id="getval"></span>

</body>
</html>