Hi,
I am new in using JQuery, so now I only know is getting the value of one textbox. But now I need to get the value of the first textbox which is the process id. So that on my query on getting the machine I could also base on what process.
here is my code:
<?php
error_reporting(0);
session_start();
ob_start();
date_default_timezone_set("Asia/Singapore");
include('connection.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>Operator's Shift Report </title>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
//----auto complete process name---//
$().ready(function() {
$("#process_name").autocomplete("get_process_list.php", {
width: 205,
matchContains: true,
mustMatch: true,
selectFirst: false
});
$("#process_name").result(function(event, data, formatted) {
$("#process_id").val(data[1]);
});
});
//------auto complete machine 1---//
$().ready(function() {
$("#machine_1").autocomplete("get_machine_1.php", {
width: 205,
matchContains: true,
mustMatch: true,
selectFirst: false
});
$("#machine_1").result(function(event, data, formatted) {
$("#ma_1").val(data[1]);
});
});
</script>
</head>
<body>
<form name="operator_report" action="<?php echo $PHP_SELF; ?>" method="post" autocomplete="off">
<!--Tab List -->
</div>
<div id="operators_report">
<fieldset>
<legend><h1>Operator's Shift Report</h1></legend>
<table>
<td>Process:</td>
<td><input type="text" name="process_name" id="process_name" value="" size="30" ></td>
<td>Machine 1: </td>
<td><input type="text" name="machine_1" id="machine_1" value="" size="30"></td>
</tr>
</table>
</fieldset>
</div>
<input type="text" name="process_id" id="process_id" value="" />
<input type="text" name="ma_1" id="ma_1" value="" />
<div id="op_output_fieldset">
</div>
</form>
</body>
</html>
here is my code in getting the machine name
//—in this code I just want to get the process_id, but I have no idea what jquery code should I need to use to get the value of process_id.
<?php
ob_start();
include "connection.php";
$q = strtolower($_GET["q"]);
//if (!$q) return;
if ($q == '') {
header("HTTP/1.0 404 Not Found", true, 404);
}
else
{
$sql = "select machine_id, machine_name from machine_list where machine_name LIKE '$q%'";
$rsd = mysql_query($sql);
$cnt = mysql_num_rows($rsd);
if($cnt > 0)
{
while($rs = mysql_fetch_array($rsd)) {
$sid = $rs['machine_id'];
$sname = $rs['machine_name'];
echo "$sname|$sid\
";
}
}
else
{
header("HTTP/1.0 404 Not Found", true, 404);
}
}
?>
Thank you
Whenever the process id is changed, you’ll want to update the machine_1 autocomplete. You can do that by updating the source information on its autocomplete so that it includes the processid information.
$("#process_name").result(function(event, data, formatted) {
var processId = data[1],
querystring = '';
$("#process_id").val(processId);
if (processId) {
querystring = '?processid=' + encodeURIComponent($("#process_id").val());
}
$("#machine_1").autocomplete('option', 'source', 'get_machine_1.php' + querystring);
That should update the autocomplete query to get_machine_1.php so that a request is made to get_machine_1.php?processid=12345&term=abc
so that it has a processid key, as well as the usual term key.
Where should I put that code?
and how can i call or get the process id on my get_machine_1.php?
Thank you
You can use it to replace this part:
$("#process_name").result(function(event, data, formatted) {
$("#process_id").val(data[1]);
});
I suspect that filter_input will be a good way to get that info, but that’s a question for which the PHP forum will be best able to answer.
I’ll move this thread over to the PHP forum so that they can weigh in on this.
Hi…
I tried this code:
//----auto complete process name---//
$().ready(function() {
$("#process_name").autocomplete("get_process_list.php", {
width: 205,
matchContains: true,
mustMatch: true,
selectFirst: false
});
$("#process_name").result(function(event, data, formatted) {
$("#process_id").val(data[1]);
});
$("#process_name").result(function(event, data, formatted) {
$("#machine_id").val(data[2]);
});
$("#process_name").result(function(event, data, formatted) {
$("#machine_1").val(data[3]);
});
$("#process_name").result(function(event, data, formatted) {
$("#machine_2").val(data[3]);
});
});
and the php code:
$sql = "select p.process_id, p.process_name, m.machine_id, m.machine_name
from process_list AS p JOIN machine_list AS m ON (p.process_id = m.machine_process_id)
where process_name LIKE '%$q%'";
$rsd = mysql_query($sql);
$cnt = mysql_num_rows($rsd);
if($cnt > 0)
{
while($rs = mysql_fetch_array($rsd)) {
$pid = $rs['process_id'];
$pname = $rs['process_name'];
$mid = $rs['machine_id'];
$mname = $rs['machine_name'];
echo "$pname|$pid|$mid|$mname\
";
}
}
when I choose process name it automatically displayed the first machine name on the machine_1 textbox and on the machine_2 textbox.
but i want to happen is it only displayed all the machine list on the machine_1 when I start type on the machine_1 textbox which is connected the value to process_id. Is it possible?
Thank you
Or in this code:
$().ready(function() {
$("#machine_1").autocomplete("get_machine_1.php", {
width: 205,
matchContains: true,
mustMatch: true,
selectFirst: false
});
$("#machine_1").result(function(event, data, formatted) {
$("#ma_1").val(data[1]);
});
});
how can i get also the process_id?
so that I can get on my php file:
<?php
ob_start();
include "connection.php";
//--like this
$process_id = $_GET['process_id'];
$q = strtolower($_GET["q"]);
//if (!$q) return;
if ($q == '') {
header("HTTP/1.0 404 Not Found", true, 404);
}
else
{
$sql = "select machine_id, machine_name from machine_list where machine_name LIKE '$q%'";
$rsd = mysql_query($sql);
$cnt = mysql_num_rows($rsd);
if($cnt > 0)
{
while($rs = mysql_fetch_array($rsd)) {
$sid = $rs['machine_id'];
$sname = $rs['machine_name'];
echo "$sname|$sid\
";
}
}
else
{
header("HTTP/1.0 404 Not Found", true, 404);
}
}
?>
Thank you