我使用Jquery/AJAX,PHP和MySQL來完成這個程序。jQuery + MySQL檢查文本框的值?
我有3個文本框(模式,項目和數量也提交按鈕)
它是如何工作
(1)。用戶輸入模式,然後輸入項目,然後用戶按TABKEY。去數量TEXTBOX。 (2)。我有mysql表tbl_master它包含模式和項目。 (一個圖案有很多項目)。
(3)。系統檢查用戶輸入的Pattern和Item是否匹配。
這是我的界面。 interface
我需要爲此表單添加5項和5項。 (我試過,但它僅僅只檢查第一項文本框)
example
請幫我做這個
我的代碼
registration.php的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="en-us" http-equiv="Content-Language">
<title>:: Stores-Stock ::</title>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/settings.js" type="text/javascript"></script>
<SCRIPT type="text/javascript">
pic1 = new Image(16, 16);
pic1.src = "loader.gif";
$(document).ready(function(){
$("#username").change(function() {
var usr = $("#username").val();
var pat = $("#pattern").val();
if(usr.length >= 3)
{
$("#status").html('<img src="loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "check.php",
data: "username="+ usr+ "&pattern=" + pat,
success: function(msg){
$("#status").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
$("#username").removeClass('object_error'); // if necessary
$("#username").addClass("object_ok");
$(this).html(' <font color="Green"> ok </font> ');
}
else
{
$("#username").removeClass('object_ok'); // if necessary
$("#username").addClass("object_error");
$(this).html(msg);
}
});
}
});
}
else
{
$("#status").html('<font color="red">The username should have at least <strong>3</strong> characters.</font>');
$("#username").removeClass('object_ok'); // if necessary
$("#username").addClass("object_error");
}
});
});
//-->
</SCRIPT>
<style type="text/css">
body{
font-family:"Trebuchet MS";
font-size:12px;
}
.inn{
float:left;
font-size:14px;
border:solid 1px #000000;
width:143px;
font-family:Arial, Helvetica, sans-serif;
color:#0066CC;
font-weight:bold;
}
.qty {
float:left;
font-size:14px;
border:solid 1px #000000;
width:50px;
font-family:Arial, Helvetica, sans-serif;
color:#0066CC;
font-weight:bold;
}
</style>
</head>
<body>
<p> </p>
<p><strong><center>
<strong>FINISH GOOD </strong> STORES STOCK
</center></strong></p>
<p> </p>
<table width="499" align="center" >
<tr>
<td width="170" align="right" valign="middle" id="abc4">Pattern : </td>
<td width="317" align="left" valign="middle" ><input id="pattern" type="text" name="pattern" onkeyup="twitter.updateUrl(this.value)" class="inn" />
</td>
</tr>
</table>
<form name="form1" method="post" action="submit.php">
<table width="499" align="center" >
<tr>
<td width="170" align="right" valign="middle" id="abc">Item :</td>
<td width="191" align="left" valign="middle" ><input id="username" type="text" name="username" onkeyup="twitter.updateUrl(this.value)" class="inn" />
</td>
<td width="120" align="left" valign="middle" nowrap="nowrap" >Qty :
<input name="qty" type="text" class="qty" id="qty" size="10" maxlength="10" /></td>
</tr>
<tr>
<td></td>
<td height="20px" colspan="2" align="left" valign="bottom"><div id="status"></div></td>
</tr>
</table>
<p> </p>
</form>
<script type="text/javascript">
$(function() {
twitter.screenNameKeyUp();
$('#user_screen_name').focus();
});
</script>
</body></html>
檢查。 php
<?php
// This is a sample code in case you wish to check the username from a mysql db table
if(isset($_POST['username']))
{
$username = $_POST['username'];
// $username = $_POST['username2'];
$pattern = $_POST['pattern'];
include("dbconnection.php");
$sql_check = mysql_query("SELECT item FROM item_master WHERE pattern='$pattern' AND item='$username'");
if(mysql_num_rows($sql_check))
{
echo 'OK';
}
else
{
echo '<font color="red">Plase Check item <STRONG>'.$username.'</STRONG> again.</font>';
}
}
?>
所以你的表單總是有5行的項目和數量字段或可以改變?此外,您的圖案文本字段不包含在窗體中,是否意味着這樣? – martincarlin87
總是在5個項目和數量字段。 - 謝謝 – 9pixle