ช่วยหน่อยครับ ทำไปทำไมาไม่ได้ซะงั้น combobox select
index.php##
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"> ]
<?
if($_GET['showpage']=="search")
{
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td valign=\"top\">"; require_once('cnctools.php'); echo"</td>";
echo "</tr>";
echo"</table>";
}
?>
</td>
</tr>
</table>
#######################
cnctools.php##
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(obj) {
var req = Inint_AJAX();
var Ttype = document.getElementById( 'toolstype' ).value;
//var Tname = document.getElementById( 'toolsname' ).value;
var Tteeth = document.getElementById( 'toolsteeth' ).value;
var Tdia = document.getElementById( 'toolsdia1' ).value;
if ( obj && obj.name == 'toolstype' )
{
var Tname="";
}
else
{
var Tname = document.getElementById( 'toolsname' ).value;
};
var data = "toolstype=" + Ttype + "&toolsname=" + Tname + "&toolsteeth=" + Tteeth + "&toolsdia1=" + Tdia;
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
var datas = eval( '(' + req.responseText + ')' );
document.getElementById( 'toolstypeDiv' ).innerHTML = datas[0].toolstype;
document.getElementById( 'toolsnameDiv' ).innerHTML = datas[0].toolsname;
document.getElementById( 'toolsteethDiv' ).innerHTML = datas[0].toolsteeth;
document.getElementById( 'toolsdia1Div' ).innerHTML = datas[0].toolsdia1;
//document.getElementById(src).innerHTML=req.responseText; //รับค่ากลับมา
}
}
};
req.open("POST", "toolssearch.php",true); //สร้าง connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
req.send(data); //ส่งค่า
};
window.onload = function()
{
dochange( '' );
};
</script>
<table width="99%" border="0" cellspacing="0" cellpadding="0" bordercolor="#A7A7A5" align="center">
<tr>
<td>
<form action=\"\" method=\"post\">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<?
global $paramLabel;
$tools_type = $_POST[toolstype];
$tools_name = $_POST[toolsname];
$tools_teeth = $_POST[toolsteeth];
$tools_dia1 = $_POST[toolsdia1];
?>
<tr>
<td width="40%" height="27"><div align="right">Type : </div></td>
<td width="60%"><span id="toolstypeDiv"> <select name="toolstype" id="toolstype" onchange="dochange('toolstype')">\n<option value="<? echo $tools_type; ?>">m Choose type </option></select></span></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Name Tools : </div></td>
<td width="60%"><span id="toolsnameDiv"> <select name="toolsname" id="toolsname" onchange="dochange('toolsname')">\n<option value="<? echo $tools_name; ?>"> Choose name </option></select></span></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Flute : </div></td>
<td width="60%"><span id="toolsteethDiv"> <select name="toolsteeth" id="toolsteeth" onchange="dochange('toolsteeth')">\n<option value="<? echo $tools_teeth; ?>"> Choose flute </option></select></span></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Diameter : </div></td>
<td width="60%"><span id="toolsdia1Div"> <select name="toolsdia1" id="toolsdia1" onchange="dochange('toolsdia1')">\n<option value="<? echo $tools_dia1; ?>"> Choose diameter </option></select></span></td>
</tr>
<? /* <tr>
<td width="40%" height="27"><div align="right">Cut Length : </div></td>
<td width="60%"> <font id="toolssize1"><select><option value="0">=========================</option></select></font></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Shank Diameter : </div></td>
<td width="60%"> <font id="toolsdia2"><select><option value="0">=========================</option></select></font></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Over all Length : </div></td>
<td width="60%"> <font id="toolssize2"><select><option value="0">=========================</option></select></font></td>
</tr>*/?>
<tr>
<td width="40%" height="33"><div align="right"> </div></td>
<td width="60%"><input type="submit" name="Submit" value="Search"> <INPUT type="reset" value="Clear"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
#################################
toolssearch.php##
<?
require_once("includes/database.php");
Conn2DB();
//$data = $_GET['data'];
//$val = $_GET['val'];
$_toolstype = $_POST[toolstype];
$_toolsname = $_POST[toolsname];
$_toolsteeth = $_POST[toolsteeth];
$_toolsdia1 = $_POST[toolsdia1];
$result=mysql_query("SELECT id,name,ref,showlink FROM tb_toolstype WHERE showlink='Y' ORDER BY id");
echo "[{\"toolstype\":\"";
echo "<select name='toolstype' id='toolstype' onChange=\"dochange(this)\">";
echo "<option value='0'> Choose type </option>";
while($row = mysql_fetch_array($result)){
echo "<option value=\"$row[ref]\"";
if ($_toolstype == $row[ref])
{
echo "selected='selected'";
}
echo ">$row[name]</option>";
}
echo "</select>\",\"toolsname\":\"";
echo "<select name='toolsname' id='toolsname' onChange=\"dochange(this)\">";
if ($_toolstype != "0" && $_toolstype != "") {
echo "<option value='0'> Choose name </option>";
$result1=mysql_db_query($dbname,"SELECT * FROM tb_tools WHERE showlink='Y' AND ref_type='$_toolstype' GROUP BY ref_name ORDER BY id");
while($row1 = mysql_fetch_array($result1)){
echo "<option value=\"$row1[ref_name]\"";
if ($_toolstype == $row1[ref_name])
{
echo "selected='selected'";
}
echo ">$row1[ref_name]</option>";
}
}
else {
echo "<option value=''> Choose name </option>";
}
//echo "</select>\",\"toolsteeth\":\"";
//echo "<select name='toolsteeth' id='toolsteeth' onChange=\"dochange(this)\">";
//echo "</select>\",\"toolsdia1\":\"";
//echo "<select name='toolsdia1' id='toolsdia1' onChange=\"dochange(this)\">";
echo "</select>\"}]";
?>
#################
มันไม่ทำงานตั้งแต่ windows onload ครับ ไม่ไม่อะไรให้เลือกเลย
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top"> ]
<?
if($_GET['showpage']=="search")
{
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<tr>";
echo "<td valign=\"top\">"; require_once('cnctools.php'); echo"</td>";
echo "</tr>";
echo"</table>";
}
?>
</td>
</tr>
</table>
#######################
cnctools.php##
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(obj) {
var req = Inint_AJAX();
var Ttype = document.getElementById( 'toolstype' ).value;
//var Tname = document.getElementById( 'toolsname' ).value;
var Tteeth = document.getElementById( 'toolsteeth' ).value;
var Tdia = document.getElementById( 'toolsdia1' ).value;
if ( obj && obj.name == 'toolstype' )
{
var Tname="";
}
else
{
var Tname = document.getElementById( 'toolsname' ).value;
};
var data = "toolstype=" + Ttype + "&toolsname=" + Tname + "&toolsteeth=" + Tteeth + "&toolsdia1=" + Tdia;
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
var datas = eval( '(' + req.responseText + ')' );
document.getElementById( 'toolstypeDiv' ).innerHTML = datas[0].toolstype;
document.getElementById( 'toolsnameDiv' ).innerHTML = datas[0].toolsname;
document.getElementById( 'toolsteethDiv' ).innerHTML = datas[0].toolsteeth;
document.getElementById( 'toolsdia1Div' ).innerHTML = datas[0].toolsdia1;
//document.getElementById(src).innerHTML=req.responseText; //รับค่ากลับมา
}
}
};
req.open("POST", "toolssearch.php",true); //สร้าง connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
req.send(data); //ส่งค่า
};
window.onload = function()
{
dochange( '' );
};
</script>
<table width="99%" border="0" cellspacing="0" cellpadding="0" bordercolor="#A7A7A5" align="center">
<tr>
<td>
<form action=\"\" method=\"post\">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<?
global $paramLabel;
$tools_type = $_POST[toolstype];
$tools_name = $_POST[toolsname];
$tools_teeth = $_POST[toolsteeth];
$tools_dia1 = $_POST[toolsdia1];
?>
<tr>
<td width="40%" height="27"><div align="right">Type : </div></td>
<td width="60%"><span id="toolstypeDiv"> <select name="toolstype" id="toolstype" onchange="dochange('toolstype')">\n<option value="<? echo $tools_type; ?>">m Choose type </option></select></span></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Name Tools : </div></td>
<td width="60%"><span id="toolsnameDiv"> <select name="toolsname" id="toolsname" onchange="dochange('toolsname')">\n<option value="<? echo $tools_name; ?>"> Choose name </option></select></span></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Flute : </div></td>
<td width="60%"><span id="toolsteethDiv"> <select name="toolsteeth" id="toolsteeth" onchange="dochange('toolsteeth')">\n<option value="<? echo $tools_teeth; ?>"> Choose flute </option></select></span></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Diameter : </div></td>
<td width="60%"><span id="toolsdia1Div"> <select name="toolsdia1" id="toolsdia1" onchange="dochange('toolsdia1')">\n<option value="<? echo $tools_dia1; ?>"> Choose diameter </option></select></span></td>
</tr>
<? /* <tr>
<td width="40%" height="27"><div align="right">Cut Length : </div></td>
<td width="60%"> <font id="toolssize1"><select><option value="0">=========================</option></select></font></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Shank Diameter : </div></td>
<td width="60%"> <font id="toolsdia2"><select><option value="0">=========================</option></select></font></td>
</tr>
<tr>
<td width="40%" height="27"><div align="right">Over all Length : </div></td>
<td width="60%"> <font id="toolssize2"><select><option value="0">=========================</option></select></font></td>
</tr>*/?>
<tr>
<td width="40%" height="33"><div align="right"> </div></td>
<td width="60%"><input type="submit" name="Submit" value="Search"> <INPUT type="reset" value="Clear"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
#################################
toolssearch.php##
<?
require_once("includes/database.php");
Conn2DB();
//$data = $_GET['data'];
//$val = $_GET['val'];
$_toolstype = $_POST[toolstype];
$_toolsname = $_POST[toolsname];
$_toolsteeth = $_POST[toolsteeth];
$_toolsdia1 = $_POST[toolsdia1];
$result=mysql_query("SELECT id,name,ref,showlink FROM tb_toolstype WHERE showlink='Y' ORDER BY id");
echo "[{\"toolstype\":\"";
echo "<select name='toolstype' id='toolstype' onChange=\"dochange(this)\">";
echo "<option value='0'> Choose type </option>";
while($row = mysql_fetch_array($result)){
echo "<option value=\"$row[ref]\"";
if ($_toolstype == $row[ref])
{
echo "selected='selected'";
}
echo ">$row[name]</option>";
}
echo "</select>\",\"toolsname\":\"";
echo "<select name='toolsname' id='toolsname' onChange=\"dochange(this)\">";
if ($_toolstype != "0" && $_toolstype != "") {
echo "<option value='0'> Choose name </option>";
$result1=mysql_db_query($dbname,"SELECT * FROM tb_tools WHERE showlink='Y' AND ref_type='$_toolstype' GROUP BY ref_name ORDER BY id");
while($row1 = mysql_fetch_array($result1)){
echo "<option value=\"$row1[ref_name]\"";
if ($_toolstype == $row1[ref_name])
{
echo "selected='selected'";
}
echo ">$row1[ref_name]</option>";
}
}
else {
echo "<option value=''> Choose name </option>";
}
//echo "</select>\",\"toolsteeth\":\"";
//echo "<select name='toolsteeth' id='toolsteeth' onChange=\"dochange(this)\">";
//echo "</select>\",\"toolsdia1\":\"";
//echo "<select name='toolsdia1' id='toolsdia1' onChange=\"dochange(this)\">";
echo "</select>\"}]";
?>
#################
มันไม่ทำงานตั้งแต่ windows onload ครับ ไม่ไม่อะไรให้เลือกเลย