新手自学,
用php作了个仓库的进出库,,,
例如有5个input框,我在第一个里面输入001,回车(或其它办法),第二.三.四个框自动返回物品的名字,价格,库存数量,
然后我在第五个框内输入出库数目,submit提交
请问怎么实现这个 回车后自动搜索返回数据,
谢谢
用php作了个仓库的进出库,,,
例如有5个input框,我在第一个里面输入001,回车(或其它办法),第二.三.四个框自动返回物品的名字,价格,库存数量,
然后我在第五个框内输入出库数目,submit提交
请问怎么实现这个 回车后自动搜索返回数据,
谢谢
解决方案 »
- 一个项目的简单问题,紧急求助
- 如何实现 当点击完一个链接后.链接就变色的功能?
- 快疯了!就是无法输出中文!找不到究竟是什么样原因~
- 一个php页面中include多个数据库连接(有本地的 也有远程的)时 sql语句怎么写???
- 寻PHP的虚拟主机服务商,有要求
- 如何把PHP程序改写成ASP程序
- Can't lock file (errno: 9)
- ???請高手指教,我能在客戶端 javascript 中用服務端session_register注冊的session變量不??? 能的話怎樣做,不能用什麼方法來代替???
- php设置中config的配置.
- 新手求教,php源码里面是乱七八糟的内容看不懂怎么办
- 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=gb2312" />
<title>计算器</title>
</head><script language="JavaScript" type="text/javascript">
function isnum(phone)
{
var phoneNum = "1234567890.";
var temp;
for (var i = 0; i < phone.length; i++)
{
temp = phone.substring(i,i+1);
if (phoneNum.indexOf(temp) == -1)
{
return (false);
}
}
}
function nulls(obj){
obj.house2.value='';
obj.house3.value='';
obj.fkz03.value='';
obj.fkz00.value='';
obj.yh02.value='';
obj.dkz00.value='';
obj.q02.value='';
obj.shf00.value='';
obj.wt02.value='';
obj.yj00.value='';
obj.fw02.value='';
obj.hkz00.value='';
obj.fkz003.value='';
obj.lxfd00.value='';
obj.textfield3.value='';
obj.textfield4.value='';
return false;}function runjs3(obj){//检查是否数字
var txt = document.getElementById("textfield4").value
if(txt.search("^-?\\d+(\\.\\d+)?$")!=0){
alert("请输入一个数字!");
document.getElementById("textfield4").focus();
return false;
}
//检查是否整数
txt = document.getElementById("textfield4").value
if(txt.search("^-?\\d+$")!=0){
alert("请输入一个整数!");
document.getElementById("textfield4").focus();
return false;
}
var txt2 = document.getElementById("textfield3").value
if(txt2.search("^-?\\d+(\\.\\d+)?$")!=0){
alert("请输入一个数字!");
document.getElementById("textfield3").focus();
return false;
}
if (obj.house2.value=='')
{
alert("请填写面积!");
form1.house2.focus();
return false;
}
if(obj.house2.value!="")
{
if(isnum(obj.house2.value)==false)
{
alert("销售面积填写错误!");
obj.house2.focus();
return false
}
}
if (obj.house3.value=='')
{
alert("请填写房价!");
form1.house3.focus();
return false;
}
if(obj.house3.value!="")
{
if(isnum(obj.house3.value)==false)
{
alert("房价填写错误!");
obj.house3.focus();
return false
}
} var dj=parseFloat(obj.house3.value); //单价
var mj=parseFloat(obj.house2.value); //面积
var fkz=dj*mj; //总房款
var yh=fkz*0.0005; //印花税
var qsbs=0.015 //alert(yh);
/*if (obj.house2.value>144){qsbs=0.03}else{qsbs=0.015}*/
if ((obj.house2.value>140) || (obj.house3.value>8263.2)){qsbs=0.03}else{qsbs=0.015}
var q=fkz*qsbs;
var fw=mj*1.36;
var gzh=fkz*0.02;
var hj=yh+fkz+q+gzh+fw
obj.yh02.value=Math.round(yh*100,5)/100;
obj.fkz03.value=Math.round(fkz*100,5)/100;
obj.q02.value=Math.round(q*100,5)/100;
obj.wt02.value=Math.round(gzh*100,5)/100;
obj.fw02.value=Math.round(fw*100,5)/100;
obj.fkz003.value=Math.round(hj*100,5)/100;
chsh=parseInt(100-obj.textfield3.value)/100; //按揭百分比
nsh=parseInt(obj.textfield4.value); //按揭年数
qsh=12*nsh; //按揭月数
//if(nsh==1) ylx=parseFloat(0.0635); //一年利率
//if(nsh>=2 && nsh<=3) ylx=parseFloat(0.0635); //两年利率
//if(nsh>=5 && nsh<=30) ylx=parseFloat(0.0666); //三年利率
ylx=parseFloat(0.03465); //利率
lx=ylx/12; //月利率
if (obj.house2.value>90){shf=fkz*0.3}else{shf=fkz*0.2} //dkz=(fkz-shf)*chsh;
dkz=fkz*chsh;
//dkz=fkz*chsh;
dkz1=Math.floor(dkz/10000)*10000
yj=(lx/(1-(1/(Math.pow(1+lx,qsh)))))*dkz1;
hkz=yj*qsh; obj.fkz00.value=Math.round(fkz*100,5)/100;
//obj.dkz00.value=Math.floor(dkz/10000)*10000;
obj.dkz00.value=dkz;
//obj.shf00.value=Math.round((fkz-dkz1)*100,5)/100;
//obj.shf00.value=shf;
//obj.shf00.value=Math.round((fkz-dkz1)*100,5)/100 ;
obj.shf00.value=Math.round(fkz-dkz) ;
obj.yj00.value=Math.round(yj*100,5)/100 ;
obj.hkz00.value=Math.round(hkz*100,5)/100;
obj.lxfd00.value=Math.round((hkz-dkz1)*100,5)/100;
return false;
}
</script>你改进下就行!
<body>
<div align="center"><table width="640px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><table>
<tr><td><form action="" method="post" name="form1" id="form1" onsubmit="return false">
<table width="640" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="90" align="center" bgcolor="#E8F5D8">销售面积:</td>
<td width="132" align="left" bgcolor="#E8F5D8"><input name="house2" type="text" id="house2" value="" size="15" /></td>
<td width="61" align="left" bgcolor="#E8F5D8">平方米</td>
<td width="87" align="center" bgcolor="#E8F5D8">首付百分比:</td>
<td width="139" align="left" bgcolor="#E8F5D8"><input name="textfield3" type="text" id="textfield3" value="" size="15" /></td>
<td width="41" align="left" bgcolor="#E8F5D8">%</td>
</tr>
<tr>
<td height="5" colspan="6"></td>
</tr>
<tr>
<td align="center" bgcolor="#E8F5D8">单 价:</td>
<td align="left" bgcolor="#E8F5D8"><input name="house3" type="text" id="house3" value="" size="15" /></td>
<td bgcolor="#E8F5D8">元/平方米</td>
<td align="center" bgcolor="#E8F5D8">按揭年数:</td>
<td align="left" bgcolor="#E8F5D8"><input name="textfield4" type="text" id="textfield4" value="" size="15" /></td>
<td bgcolor="#E8F5D8">年</td>
</tr>
<tr>
<td height="5" colspan="6"></td>
</tr>
<tr>
<td height="40" colspan="6" align="center" bgcolor="#E8F5D8"><input type="button" name="button" id="button" value="计算结果" onclick="return runjs3(this.form)" />
<input type="submit" name="button2" id="button2" value="重填" onclick="return nulls(this.form)" /></td>
</tr>
<tr>
<td colspan="6"> </td>
</tr>
</table>
<table width="640" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="90" align="center" bgcolor="#E8F5D8">房款总价</td>
<td width="132" align="left" bgcolor="#E8F5D8"><input name="fkz03" type="text" id="fkz03" value="" size="15" /></td>
<td width="61" align="left" bgcolor="#E8F5D8">元</td>
<td width="87" align="center" bgcolor="#E8F5D8">房款总价</td>
<td width="139" align="left" bgcolor="#E8F5D8"><input name="fkz00" type="text" id="fkz00" value="" size="15" /></td>
<td width="41" align="left" bgcolor="#E8F5D8">元</td>
</tr>
<tr align="center">
<td height="5" colspan="6"></td>
</tr>
<tr>
<td align="center" bgcolor="#E8F5D8">印花税</td>
<td align="left" bgcolor="#E8F5D8"><input name="yh02" type="text" id="yh02" value="" size="15" /></td>
<td align="left" bgcolor="#E8F5D8">元</td>
<td align="center" bgcolor="#E8F5D8">贷款总额</td>
<td align="left" bgcolor="#E8F5D8"><input name="dkz00" type="text" id="dkz00" value="" size="15" /></td>
<td align="left" bgcolor="#E8F5D8">元</td>
</tr>
<tr align="center">
<td height="5" colspan="6"></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#E8F5D8">契税</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="q02" type="text" id="q02" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
<td height="30" align="center" bgcolor="#E8F5D8">首期付款</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="shf00" type="text" id="shf00" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
</tr>
<tr align="center">
<td height="5" colspan="6"></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#E8F5D8">公共维修基金</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="wt02" type="text" id="wt02" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
<td height="30" align="center" bgcolor="#E8F5D8">月均还款</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="yj00" type="text" id="yj00" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
</tr>
<tr align="center">
<td height="5" colspan="6"></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#E8F5D8">测绘费金</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="fw02" type="text" id="fw02" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
<td height="30" align="center" bgcolor="#E8F5D8">还款总额</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="hkz00" type="text" id="hkz00" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
</tr>
<tr align="center">
<td height="5" colspan="6" bgcolor="#FFFFFF"></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#E8F5D8">合计</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="fkz003" type="text" id="fkz003" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
<td height="30" align="center" bgcolor="#E8F5D8">支付利息</td>
<td height="30" align="left" bgcolor="#E8F5D8"><input name="lxfd00" type="text" id="lxfd00" value="" size="15" /></td>
<td height="30" align="left" bgcolor="#E8F5D8">元</td>
</tr>
</table>
<a href="http://bj.house.sina.com.cn/bxjsq/" target="_blank" style="color:#666666;"><br />
更多购房计算器 >>></a><br />
</form></td></tr></table>
</td>
</tr>
</table> </tr>
</table></td>
</tr>
</table>
</div>
</body>
</html>
但是汉字返回时乱码,(物品名字英文正常),,怎么解决,我设的是gbk,,,mysql_query("SET NAMES 'gbk'");<script type="text/javascript">
var xmlHttpfunction showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="getcustomer.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script><div>
<form>
<input type="text" name="customers" onchange="showCustomer(this.value)" size="12" />
</form>
</div><div id="txtHint">客户信息将在此处列出。</div>
但是乱码,
设置的gbk,普通搜索可以正常显示汉字,这样调用ajax/js 再返回值中文就乱码,英文正常,帮我看一下哪里有问题
<script type="text/javascript">
var xmlHttpfunction showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;
}
var url="getcustomer.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script><div>
<form>
<input type="text" name="customers" onchange="showCustomer(this.value)" size="12" />
</form>
</div><div id="txtHint">客户信息将在此处列出。</div>下面是调用的php文件代码,<?php
$conn = mysql_connect("localhost","root","")
or die("could not connect:".mysql_error());
//if(!$conn) echo "连接不上数据库<br>";else echo"数据库连接成功";
mysql_select_db("sgz",$conn);
mysql_query("SET NAMES 'gbk'");
$sql = "select depot_id,depot_name from depot where depot_id=".$_GET['q'];
$result = mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo "depotid=".$row['depot_id']."<br />";
echo "depotname=".$row['depot_name']."<br />";
} mysql_close($conn);
?>
if(isNaN($(this).val())){
alert('请输入数字类型!');
}
})
mysql_query("SET NAMES 'gbk'");
....
换成 mysql_set_charset('gb2312',$conn);试试