Hi all, I have this code that seems to work fine for the order but cant get it to pass the invoice side of things. the trouble im having is when i do the order its fine, but when i do an invoice it sends me back to the order creating form for some reason. Help please! New Ajax learner!
This is the ajax script:
<script type="text/javascript">
function showitem(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
var OrderID = document.getElementById("orderID");
var QuoteID = document.getElementById("quoteID");
var InvoiceID = document.getElementById("invoiceID");
}
}
xmlhttp.open("GET","/items/getitem.php?orderID=OrderID"eID=QuoteID&invoiceID=InvoiceID&q="+str,true);
xmlhttp.send();
}
</script>
This is the form that is on the order / quote / invoice creating page in php, the id is changed on the respective pages, the invoice page is where im having trouble, its fine when its orderID
echo "<div class='box'>
<form>
Search for an Item:
<input type='hidden' id='invoiceID' value='$invoiceID'><input type='text' value='' onkeyup='showitem(this.value)'>
</form>
<br />
<div id='txtHint'></div></div>";
This is the item add to page which isn't seen as it is the processing page for items:
<?php
include("../config.php");
connect();
$submit = $_REQUEST['submit'];
$view = $_REQUEST['view'];
$quoteID = $_REQUEST['quoteID'];
$orderID = $_REQUEST['orderID'];
$invoiceID = $_REQUEST['invoiceID'];
$itemID = $_REQUEST['itemID'];
$item_code =$_REQUEST['item_code'];
$description = $_REQUEST['description'];
$list_exc = $_REQUEST['list_exc'];
$trade_exc = $_REQUEST['trade_exc'];
$rrp_exc = $_REQUEST['rrp_exc'];
$quantity = $_REQUEST['quantity'];
$total_exc = $quantity * $rrp_exc;
if($submit=="Add")
{
if(!$quoteID=="")
{
$table = "qItems";
$docID = "quoteID";
$dir = "quotes";
$reloID = "$quoteID";
}
if(!$invoiceID=="")
{
$table = "iItems";
$docID = "invoiceID";
$dir = "invoices";
$reloID = "$invoiceID";
}
if(!$orderID=="")
{
$table = "oItems";
$docID = "orderID";
$dir = "orders";
$reloID = "$orderID";
}
mysql_query("INSERT INTO `$table` (`$docID`, `itemID`, `item_code`, `description`, `list_exc`, `trade_exc`, `rrp_exc`, `quantity`, `total_exc`)
VALUES ('$reloID', '$itemID', '$item_code', '$description', '$list_exc', '$trade_exc', '$rrp_exc', '$quantity', '$total_exc')");
}
if($submit=="Delete")
{
if(!$quoteID=="")
{
$table = "qItems";
$docID = "quoteID";
$dir = "quotes";
$reloID = "$quoteID";
}
if(!$invoiceID=="")
{
$table = "iItems";
$docID = "invoiceID";
$dir = "invoices";
$reloID = "$invoiceID";
}
if(!$orderID=="")
{
$table = "oItems";
$docID = "orderID";
$dir = "orders";
$reloID = "$orderID";
}
$quantity = $_REQUEST['quantity'];
mysql_query("DELETE FROM `$table` WHERE `$docID` = '$reloID' AND `itemID` = '$itemID' and `quantity` = '$quantity'");
}
header("location: ../$dir/vied.php?view=Update&$docID=$reloID");
?>
and this is the get item page that the ajax is calling:
<?php
include("../config.php");
$q = $_GET['q'];
$invoiceID = $_GET['invoiceID'];
$quoteID = $_GET['quoteID'];
$orderID = $_GET['orderID'];
connect();
$result = mysql_query("SELECT * FROM items WHERE description LIKE '%$q%'");
while($row = mysql_fetch_array($result))
{
echo "
<form method='post' action='/items/addTo.php'>
<input type='hidden' name='quoteID' value='$quoteID'>
<input type='hidden' name='orderID' value='$orderID'>
<input type='hidden' name='invoiceID' value='$invoiceID'>
<input type='hidden' name='itemID' value='".$row['itemID']."'>
<input type='hidden' name='list_exc' id='list' value='".$row['list_exc']."'>
<input type='hidden' name='trade_exc' value='".$row['trade_exc']."'>
<input type='hidden' name='item_code' value='" . $row['item_code'] . "'>
<input type='hidden' name='description' value='" . $row['description'] . "'>";
echo $row['description'];
echo " | ".$row['item_code'];
echo " | $".$row['list_exc'];
echo "
<br /><input type='text' title='Retail price' name='rrp_exc' id='rrp' size='6' value='" . $row['rrp_exc'] . "'>";
echo "<input type='text' title='Quantity' name='quantity' size='2' value='" . $row['quantity'] . "'>";
echo "<input type='submit' name='submit' value='Add'></form>";
}
?>