Hi all,
I did a grid with an input field using the suggestions of Hiram (ref.How add an input field to a grid…)
now I’m stucked becouse I’m not able to use the global variable available on client as JS variable (quantity) into a blank application that uses that same variable [glo_QuantityRow] to insert a record into mysql db.
Grid has under onHeader
echo '<script>
function myfunction(id, name, supplier, category, company, price, quantity){
var xmlhttp;
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)
{
console.log(xmlhttp.responseText);
}
}
xmlhttp.open(“POST”,location.href,true);
xmlhttp.setRequestHeader(“Content-type”,“application/x-www-form-urlencoded”);
xmlhttp.send(“id=”+id+"&name="+name+"&supplier="+s upplier+"&category="+category+"&company="+company+ “&price=”+price+"&quantity="+quantity.toString ());
</script>’;
and under OnRecord
if (isset($_POST[‘id’])){
[glo_ProductID] = $_POST[‘id’];
}
if (isset($_POST[‘name’])){
[glo_ProductName] = $_POST[‘name’];
}
if (isset($_POST[‘supplier’])){
[glo_SupplierID] = $_POST[‘supplier’];
}
if (isset($_POST[‘category’])){
[glo_CategoryID] = $_POST[‘category’];
}
if (isset($_POST[‘company’])){
[glo_CompanyID] = $_POST[‘company’];
}
if (isset($_POST[‘price’])){
[glo_UnitPrice] = $_POST[‘price’];
}
if (isset($_POST[‘quantity’])){
[glo_QuantityRow] = $_POST[‘quantity’];
}
{col}= “<input type=‘text’ size=‘6’ onchange='myfunction(”{ProductID}","{ProductName}","{SupplierID}","{CategoryID}","{CompanyID}","{UnitPrice}", this.value)’>";
===============
When I use the variable [glo_QuantityRow] within blank application it’s always empty
INSERT products_selected
(ProductID, CustomerID, SalesmanID, ProductName, SupplierID, CategoryID, CompanyID, SelectedDate, Quantity, UnitPrice , ProductID_altern)
VALUES
(’[glo_ProductID]’, ‘[glo_CustomerID]’, ‘[glo_SalesmanID]’ ‘[glo_ProductName]’, ‘[glo_SupplierID]’ ,
‘[glo_CategoryID]’, ‘[glo_CompanyID]’, ‘[order_date]’ , [glo_QuantityRow], [glo_UnitPrice], ‘’)
ON DUPLICATE KEY UPDATE Quantity = Quantity + [glo_QuantityRow] ";
and the echo is …
INSERT products_selected (ProductID, CustomerID, SalesmanID, ProductName, SupplierID, CategoryID, CompanyID, SelectedDate, Quantity, UnitPrice , ProductID_altern) VALUES (‘013-3881-4’, ‘ALFKI’, ‘AGE01’ ‘CA - 560’, ‘F012’ , ‘SICLSYVA’, ‘Eos’, ‘2015-01-17’ , , 0.0000, ‘’) ON DUPLICATE KEY UPDATE Quantity = Quantity +
After ‘2015-01-17’ you can see the Quantity value empty and also on very last Quantity = Quantity + is missing [glo_QuantityRow] value.
Googling I founded this suggestion but I don’t know how use it … here;-(((
<script type=“text/javascript”>
function passvariable(var){
window.location.href= ‘filename.php?var=’+var;
}
</script>
<input type=“button” value=“submit” onclick=“passvariable(’<?php echo $phpvariable;?>’);”/>