JQuery 自动完成返回选中的复选框
调用 jquery 函数后,如何从 Mysql 数据库中的布尔值中选择一个复选框?这是有的,但我不确定如何选中该复选框以及将其放在 jquery 中的位置。 (FreeShip 和 BizlicSent) 是需要输入复选框的布尔值。任何帮助将不胜感激。
$(function() {
$('#Customer_ID').val("");
$('#Name').val("");
$('#BillingEmail').val("");
$('#FreeShip').val("");
$('#BizlicSent').val("");
$("#searchterm").autocomplete({
source: "Customer.QUERY.php",
minLength: 3,
autoFocus: true,
select: function(event, ui) {
$('#Customer_ID').val(ui.item.Customer_ID);
$('#FirstName').val(ui.item.FirstName);
$('#BillingEmail').val(ui.item.BillingEmail);
$('#FreeShip').val(ui.item.FreeShip);
$('#BizlicSent').val(ui.item.BizlicSent);
}
});
});
在页面上添加更多数据的新编辑
这是具有 javascript/jquery 信息的页面
<?php include '../JQ/jquery.php';?>
<html>
<head>
<script type="text/javascript">
$(function() {
$('#Customer_ID').val("");
$('#Name').val("");
$('#BillingEmail').val("");
$('#FreeShip').val("");
$('#BizlicSent').val("");
$("#searchterm").autocomplete({
source: "Customer.QUERY.php",
minLength: 3,
autoFocus: true,
select: function(event, ui) {
$('#Customer_ID').val(ui.item.Customer_ID);
$('#FirstName').val(ui.item.FirstName);
$('#BillingEmail').val(ui.item.BillingEmail);
$('#FreeShip').attr("checked", ui.item.FreeShip);
$('#BizlicSent').attr("checked", ui.item.BizlicSent);
}
});
});
</script>
</head>
<body>
<form action="<?php echo $PHP_SELF;?>" method="post">SEARCH:
<input type="text" id="searchterm" size="60" onClick="this.form.reset()"/>
</form>
<form method="POST" name="form" id="my_form">
<input type="text" name="Customer_ID" id="Customer_ID">
Customer ID<br>
<input type="text" name="FirstName" id="FirstName">
First Name<br>
<input type="text" name="BillingEmail" id="BillingEmail">
Billing Email<br>
FreeShip<input type="checkbox" name="FreeShip" id="FreeShip"><br>
BizlicSent<input type="checkbox" name="BizlicSent" id="BizlicSent"><br>
<br>
<input type="submit" name="button" value="UPDATE">
</form>
</body>
</html>
这是查询页面。
<?php include_once '../connection.php';?>
<?php
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch(PDOException $e) {
echo $e->getMessage();
}
$return_arr = array();
if ($conn)
{
$ac_term = "%".$_GET['term']."%";
$query = "SELECT
Customer_ID, FirstName, BillingEmail, FreeShip, BizlicSent,
CONCAT_WS(' ', Customer_ID, FirstName, BillingEmail) AS displayName
FROM CustomerListNew
WHERE `Customer_ID` LIKE :term
OR `FirstName` LIKE :term
OR `BillingEmail` LIKE :term
";
$result = $conn->prepare($query);
$result->bindValue(":term",$ac_term);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['value'] = $row['displayName'];
$row_array['Customer_ID'] = $row['Customer_ID'];
$row_array['FirstName'] = $row['FirstName'];
$row_array['BillingEmail'] = $row['BillingEmail'];
$row_array['FreeShip'] = $row['FreeShip'];
$row_array['BizlicSent'] = $row['BizlicSent'];
array_push($return_arr,$row_array);
}
}
$conn = null;
echo json_encode($return_arr);
?>
这是 JSON 响应。
[{"value":"asdf asdf asdf","Customer_ID":"asdf","FirstName":"asdf","BillingEmail":"asdf","FreeShip":"1","BizlicSent":"0"},{"value":"qwer qwer qwer","Customer_ID":"qwer","FirstName":"qwer","BillingEmail":"qwer","FreeShip":"0","BizlicSent":"1"},{"value":"aaaa aaaa aaaa","Customer_ID":"aaaa","FirstName":"aaaa","BillingEmail":"aaaa","FreeShip":"1","BizlicSent":"0"},{"value":"bbbb bbbb bbbb","Customer_ID":"bbbb","FirstName":"bbbb","BillingEmail":"bbbb","FreeShip":"0","BizlicSent":"1"},{"value":"cccc cccc cccc","Customer_ID":"cccc","FirstName":"cccc","BillingEmail":"cccc","FreeShip":"1","BizlicSent":"1"},{"value":"dddd dddd dddd","Customer_ID":"dddd","FirstName":"dddd","BillingEmail":"dddd","FreeShip":"0","BizlicSent":"0"}]
After calling the jquery function how do you make a checkbox selected from a Boolean value in a Mysql database? Here's what is have, but I'm not sure how to get the check box selected and where to put it in the jquery. (FreeShip & BizlicSent) are the Boolean values that need to go into the check boxes. Any help would be greatly appreciated.
$(function() {
$('#Customer_ID').val("");
$('#Name').val("");
$('#BillingEmail').val("");
$('#FreeShip').val("");
$('#BizlicSent').val("");
$("#searchterm").autocomplete({
source: "Customer.QUERY.php",
minLength: 3,
autoFocus: true,
select: function(event, ui) {
$('#Customer_ID').val(ui.item.Customer_ID);
$('#FirstName').val(ui.item.FirstName);
$('#BillingEmail').val(ui.item.BillingEmail);
$('#FreeShip').val(ui.item.FreeShip);
$('#BizlicSent').val(ui.item.BizlicSent);
}
});
});
New Edit with more data on the pages
This is the page that have the javascript/jquery info
<?php include '../JQ/jquery.php';?>
<html>
<head>
<script type="text/javascript">
$(function() {
$('#Customer_ID').val("");
$('#Name').val("");
$('#BillingEmail').val("");
$('#FreeShip').val("");
$('#BizlicSent').val("");
$("#searchterm").autocomplete({
source: "Customer.QUERY.php",
minLength: 3,
autoFocus: true,
select: function(event, ui) {
$('#Customer_ID').val(ui.item.Customer_ID);
$('#FirstName').val(ui.item.FirstName);
$('#BillingEmail').val(ui.item.BillingEmail);
$('#FreeShip').attr("checked", ui.item.FreeShip);
$('#BizlicSent').attr("checked", ui.item.BizlicSent);
}
});
});
</script>
</head>
<body>
<form action="<?php echo $PHP_SELF;?>" method="post">SEARCH:
<input type="text" id="searchterm" size="60" onClick="this.form.reset()"/>
</form>
<form method="POST" name="form" id="my_form">
<input type="text" name="Customer_ID" id="Customer_ID">
Customer ID<br>
<input type="text" name="FirstName" id="FirstName">
First Name<br>
<input type="text" name="BillingEmail" id="BillingEmail">
Billing Email<br>
FreeShip<input type="checkbox" name="FreeShip" id="FreeShip"><br>
BizlicSent<input type="checkbox" name="BizlicSent" id="BizlicSent"><br>
<br>
<input type="submit" name="button" value="UPDATE">
</form>
</body>
</html>
This is the QUERY page.
<?php include_once '../connection.php';?>
<?php
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
}
catch(PDOException $e) {
echo $e->getMessage();
}
$return_arr = array();
if ($conn)
{
$ac_term = "%".$_GET['term']."%";
$query = "SELECT
Customer_ID, FirstName, BillingEmail, FreeShip, BizlicSent,
CONCAT_WS(' ', Customer_ID, FirstName, BillingEmail) AS displayName
FROM CustomerListNew
WHERE `Customer_ID` LIKE :term
OR `FirstName` LIKE :term
OR `BillingEmail` LIKE :term
";
$result = $conn->prepare($query);
$result->bindValue(":term",$ac_term);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['value'] = $row['displayName'];
$row_array['Customer_ID'] = $row['Customer_ID'];
$row_array['FirstName'] = $row['FirstName'];
$row_array['BillingEmail'] = $row['BillingEmail'];
$row_array['FreeShip'] = $row['FreeShip'];
$row_array['BizlicSent'] = $row['BizlicSent'];
array_push($return_arr,$row_array);
}
}
$conn = null;
echo json_encode($return_arr);
?>
Here's the JSON response.
[{"value":"asdf asdf asdf","Customer_ID":"asdf","FirstName":"asdf","BillingEmail":"asdf","FreeShip":"1","BizlicSent":"0"},{"value":"qwer qwer qwer","Customer_ID":"qwer","FirstName":"qwer","BillingEmail":"qwer","FreeShip":"0","BizlicSent":"1"},{"value":"aaaa aaaa aaaa","Customer_ID":"aaaa","FirstName":"aaaa","BillingEmail":"aaaa","FreeShip":"1","BizlicSent":"0"},{"value":"bbbb bbbb bbbb","Customer_ID":"bbbb","FirstName":"bbbb","BillingEmail":"bbbb","FreeShip":"0","BizlicSent":"1"},{"value":"cccc cccc cccc","Customer_ID":"cccc","FirstName":"cccc","BillingEmail":"cccc","FreeShip":"1","BizlicSent":"1"},{"value":"dddd dddd dddd","Customer_ID":"dddd","FirstName":"dddd","BillingEmail":"dddd","FreeShip":"0","BizlicSent":"0"}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的!这是现在有效的解决方案......
Okay! here's the solution that's working now....
缺少符号
=
。您必须使用:
The sign
=
is missing.You have to use: