Couldn't calculate drop down list select value using jquery - php

i am creating a simple inventory system using jquery.what is problem is when i calculation products we have a two option GR and KG. if i select as GR it need to be calculation the GR calculation part if i select as KG it need to be calculation the KG calculation part.i ran into the problem with KG is working GR not working what i tried so far i attached along with the image.
Form Design
<nav class="navbar navbar-dark bg-dark">
<span class="navbar-brand mb-0 h1">Restaurant Coffee Shop Pos</span>
</nav>
<tr>
<td>
<input type="checkbox" name="pos" value="Suger">
<label>Suger</label>
</td>
<td>
<input type="number" name="qty" id="qty" size="10px">
</td>
<td>
<select class="form-control" id="option" name="option"
placeholder="option" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Tea">
<label>Tea</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="option" name="option"
placeholder="Plan" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Flour">
<label> Flour</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="option" name="option"
placeholder="option" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Rice">
<label> Rice</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="status" name="status"
placeholder="Ricestatus" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Dhall">
<label> Dhall</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="Dhallstatus" name="status"
placeholder="status" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
</table>
<input type="button" class="btn btn-info" onclick="Add()" value="Ok" name="Ok" id="Ok">
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="container">
<div class="list-group-item list-group-tem-action active">AddProducts</div>
<table id="tbl-item" class="table table-dark table-bordered" cellspacing="0" width="100%" align="center">
<thead>
<tr>
<th>Delete</th>
<th>Item</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="col-sm-2">
<div class="list-group-item list-group-item-action active">Bill</div>
<div>
<label>Total</label>
<input type="text" style="color: yellow; background: black; font-size: 30px;" id="total" name="total" placeholder="Total" required>
</div>
</br>
<div>
<input type="button" class="btn btn-warning" value="Reset" name="reset" id="reset">
</div>
</div>
</div>
jQuery
<script type="text/javascript">
var tot = 0;
var total = 0;
function Add()
{
$("input[name='pos']:checked").each(function() {
// Get the value
let check = $(this).val();
var price = null;
var sugerstatus = $('#Sugerstatus :selected').text();
if (check == "Suger") {
price = 12;
}
else if (check == "Village Fries") {
price = 15;
} else if (check == "Fries") {
price = 35;
}
else if (check == "Tea")
{
price = 10;
}
else if (check == "Coffee")
{
price = 32;
}
else if (check == "Apple Juice")
{
price = 25;
}
else if (check == "Orange Juice")
{
price = 45;
}
var qty = $(this).closest("tr").find('[name="qty"]').val() || 0;
tot = qty * price;
$("#option").each(function()
{
if ($(this).val() == 2){
var calamount = (
qty * 140 );
$("#total").val(calamount);
}
if ($(this).val() == 1)
{
var calamount = (qty /1000 * 140 );
$("#total").val(calamount);
}
});
var table1 =
"<tr>" +
"<td><button type='button' name='record' class='btn btn-warning' onclick='deleterow(this)'>Delete </td>" +
"<td>" + check + "</td>" +
"<td>" + price + "</td>" +
"<td>" + qty + "</td>" +
"<td>" + tot + "</td>" +
"</tr>";
total += Number(tot);
$('#total').val(total);
$("#tbl-item tbody").append(table1);
});
}
function deleterow(e)
{
total_cost = parseInt($(e).parent().parent().find('td:last').text(),10);
total -= total_cost;
$('#total').val(total);
$(e).parent().parent().remove();
}
$('#reset').click(function()
{
location.reload();
}
);
</script>
Here
there GR value 1 KG value 2
$("#option").each(function()
{
if ($(this).val() == 2){
var calamount = (
qty * 140 );
$("#total").val(calamount);
}
if ($(this).val() == 1)
{
var calamount = (qty /1000 * 140 );
$("#total").val(calamount);
}

var tot = 0;
var total = 0;
function Add() {
$("input[name='pos']:checked").each(function() {
// Get the value
let check = $(this).val();
var price = null;
var sugerstatus = $('#Sugerstatus :selected').text();
if (check == "Suger") {
price = 12;
} else if (check == "Village Fries") {
price = 15;
} else if (check == "Fries") {
price = 35;
} else if (check == "Tea") {
price = 10;
} else if (check == "Coffee") {
price = 32;
} else if (check == "Apple Juice") {
price = 25;
} else if (check == "Orange Juice") {
price = 45;
}
var qty = $(this).closest("tr").find('[name="qty"]').val() || 0;
tot = qty * price;
var sel = $(this).closest("tr").find("select");
if (sel.val() == 2) {
var calamount = (
qty * 140);
$("#total").val(calamount);
console.log("val", sel.val(), calamount);
}
if (sel.val() == 1) {
var calamount = (qty / 1000 * 140);
$("#total").val(calamount);
console.log("val", sel.val(), calamount);
}
var table1 =
"<tr>" +
"<td><button type='button' name='record' class='btn btn-warning' onclick='deleterow(this)'>Delete </td>" +
"<td>" + check + "</td>" +
"<td>" + price + "</td>" +
"<td>" + qty + "</td>" +
"<td>" + tot + "</td>" +
"</tr>";
total += Number(tot);
$('#total').val(total);
$("#tbl-item tbody").append(table1);
});
}
function deleterow(e) {
total_cost = parseInt($(e).parent().parent().find('td:last').text(), 10);
total -= total_cost;
$('#total').val(total);
$(e).parent().parent().remove();
}
$('#reset').click(function() {
location.reload();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
<nav class="navbar navbar-dark bg-dark">
<span class="navbar-brand mb-0 h1">Restaurant Coffee Shop Pos</span>
</nav>
<div class="row">
<div class="col-sm-5">
<div class="container">
<div class="list-group-item list-group-tem-action active">Item</div>
<div class="panel-body bg-dark" style="color: white">
<form id="tbl-project">
<div class="panel-body bg-dark" style="color: white">
<table class="table table-bordered" style="color: white">
<tr>
<td>
<input type="checkbox" name="pos" value="Suger">
<label>Suger</label>
</td>
<td>
<input type="number" name="qty" id="qty" size="10px">
</td>
<td>
<select class="form-control" id="option" name="option" placeholder="option" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Tea">
<label>Tea</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="option" name="option" placeholder="Plan" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Flour">
<label> Flour</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="option" name="option" placeholder="option" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Rice">
<label> Rice</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="status" name="status" placeholder="Ricestatus" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="pos" value="Dhall">
<label> Dhall</label>
</td>
<td>
<input type="number" name="qty" size="10px">
</td>
<td>
<select class="form-control" id="Dhallstatus" name="status" placeholder="status" required>
<option value="">Please Select</option>
<option value="1">GR</option>
<option value="2">KG</option>
</select>
</td>
</tr>
</table>
<input type="button" class="btn btn-info" onclick="Add()" value="Ok" name="Ok" id="Ok">
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="container">
<div class="list-group-item list-group-tem-action active">AddProducts</div>
<table id="tbl-item" class="table table-dark table-bordered" cellspacing="0" width="100%" align="center">
<thead>
<tr>
<th>Delete</th>
<th>Item</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="col-sm-2">
<div class="list-group-item list-group-item-action active">Bill</div>
<div>
<label>Total</label>
<input type="text" style="color: yellow; background: black; font-size: 30px;" id="total" name="total" placeholder="Total" required>
</div>
</br>
<div>
<input type="button" class="btn btn-warning" value="Reset" name="reset" id="reset">
</div>
</div>
</div>
what i see its an error when you select the right select for GR or KG:
use $(this).closest("tr").find("select") instead of $("#option"), (you have to have uniq id and you have lot of id option) and no need to use loop function
var sel = $(this).closest("tr").find("select")
if (sel.val() == 2) {
var calamount = (
qty * 140);
$("#total").val(calamount);
}
if (sel.val() == 1) {
var calamount = (qty / 1000 * 140);
$("#total").val(calamount);
}
i dont figure how you calculate...

Related

how to set Dynamically Add / Remove input fields in PHP with Jquery Ajax is not working

i have written this codes and it seems not working, i have attached js and html codes, i do not know what is causing it not to work at all
$(document).ready(function() {
var i = 1;
$('#add_row').click(function() {
i++;
$('#dynamic_field').append('<tr id="row' + i + '"><td> <select data-placeholder="Choose Item..." class="form-control select2 chosen-select" tabindex="2" name="itemName[]" id="item_name1" required> <option>--Select here--</option> <?php '.$items = itemView($branchId);
while ($item = mysqli_fetch_array($items)) {.
'?> <option value="<?php '.echo $item["stockId"];.
'?>"><?php '.echo $item["itemName"];.
'?></option> <?php '.
}.
' ?></select></td><td><input type="text" name="adjustedQuantity[]" id="adjusted_Quantity1" data-srno="1" class="form-control" placeholder="Quantity" /></td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function() {
var button_id = $(this).attr("id");
$('#row' + button_id + '').remove();
});
});
<table class="table table-hover ">
<tr>
<th width="60%">Item Details</th>
<th width="30%">Quantity to Adjusted</th>
<th></th>
</tr>
<tr>
<td>
<select data-placeholder="Choose Item..." class="form-control select2 chosen-select responsive" tabindex="2" name="itemName[]" id="item_name1" required>
<option>--Select here--</option>
<?php
$items=itemView($branchId);
while ($item=mysqli_fetch_array($items)) {
?>
<option value="<?php echo $item['stockId'];?>">
<?php echo $item['itemName'];?>
</option>
<?php
}
?>
</select>
</td>
<td>
<input type="text" name="adjustedQuantity[]" id="adjusted_Quantity1" data-srno="1" class="form-control" placeholder="Quantity" />
</td>
<td>
</td>
</tr>
</table>
i have attached js and html codes, i do not know what is causing it not to work at all

After I append new row, select2 is not working

I added new row in table by jquery, then select2 is not working
// Javascript
$("#add").click(function () {
$("#mytable").each(function () {
var tds = '<tr>';
jQuery.each($('tr:last td', this), function () {
tds += '<td>' + $(this).html() +'</td>';
});
tds += '</tr>';
if ($('tbody', this).length > 0) {
$('tbody', this).append(tds);
} else {
$(this).append(tds);
}
});
});
//Html
<form method="POST" action="/store">
{{ csrf_field() }}
<h2>Invoice</h2>
<div>
<!-- Customer job-->
<div class="form-group job">
Customer job:
<select class="customer_job" name="customer_job">
#if(count($customers)>1)
#foreach($customers as $customer)
<option>{{$customer ->job}}</option>
#endforeach
#else
<p>No posts found</p>
#endif
</select>
</div>
<!--Date-->
<div class="form-group date">
Date:
<input type="date" name="date">
</div>
</div>
<br><br>
<table id="mytable">
<tr>
<th>ITEM</th>
<th>DESCRIPTION</th>
<th>QUANTITY</th>
<th>RATE</th>
<th>AMOUNT</th>
</tr>
<tr>
<td>
<select class="item" name="item">
#if(count($items)>1)
#foreach($items as $item)
<option>{{$item ->item_name}}</option>
#endforeach
#endif
</select>
</td>
<td>
<input type="text" name="description">
</td>
<td>
<input type="number" name="quantity" id="quantity" step="1">
</td>
<td>
<select class="rate" name="rate" id="rate">
#if(count($items)>1)
#foreach($items as $item)
<option>{{$item ->rate}}</option>
#endforeach
#endif
</select>
</td>
<td><input type="number" name="amount" id="amount" readonly /></td>
</tr>
</table><br>
<input type="submit" value="Save" class="submit">
<input type="button" value="Add" id="add" class="btn-primary add">
</form>
Change your js code with this code
var j =2;
$("#add").on('click', function () {
var data = '<tr><td><select class="item" name="item">#if(count($items)>1)#foreach($items as $item)<option>{{$item ->item_name}}</option> #endforeach #endif</select></td><td> <input type="text" name="description"></td> <td> <input type="number" name="quantity" id="quantity" step="1"> </td> <td> <select class="rate" name="rate" id="rate"> #if(count($items)>1) #foreach($items as $item) <option>{{$item ->rate}}</option> #endforeach #endif</select></td><td><input type="number" name="amount" id="amount" readonly /> <i class="fa fa-times-circle"></i></td></tr>';
$('#mytable tr:last').after(data);
j++;
$(".remCF").on('click', function () {
$(this).parent().parent().remove();
});
});
I hope it works

php mysql can't multiply a mysql result and a variable

I can't for the life of me figure out why i keep coming up with 0 on this ... i'm pulling a price from one of my tables and multiplying it by the quantity they are putting in in the form ... for some reason it when i try and do the math, it keeps coming up as 0 ... any help?
code:
$get_code = "SELECT * FROM products WHERE p_code LIKE '%$po_code%'";
$run_code = mysqli_query($con, $get_code);
$row_code = mysqli_fetch_array($run_code);
$count = $_POST['ord_amt'];
$price = $row_code['p_price'];
$sum_total = $price * $count;
form code:
<form action="" method="post">
<?php
include('includes/connection.php');
global $con;
$cust = "SELECT * FROM users WHERE u_id = '".$_SESSION['u_id']."'";
$r_cs = mysqli_query($con, $cust);
$rw_c = mysqli_fetch_array($r_cs);
echo "<input type='hidden' name='c_id' value='".$rw_c['c_id']."'>";
?>
<table id="datatable1" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product</th>
<th>Distal Opening</th>
<th>Material</th>
<th>Ply</th>
<th>Size</th>
<th>Length</th>
<th>Options</th>
<th>Or Enter Code (If Known)</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select class="form-control" name="prod" id="selectProd" onchange="get_prod(this.value)" required="required">
<?php get_prod_kind() ?>
</select>
</td>
<td>
<select class="form-control" name="opening" id="distOpen" required="required">
<option value="">Select Opening</option>
<option value="1">Rubberized Reinforced</option>
<option value="2">Standard Opening</option>
<option value="">None</option>
</select>
</td>
<td>
<select class="form-control" name='mat' id="selectMat" onchange="get_ply(this.value)" required="required">
</select>
</td>
<td>
<select class="form-control" name="ply" id="plySelect" onchange="get_size(this.value)" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="size" id="sizeSelect" onchange="get_len(this.value)" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="length" id="selectLength" required="required">
<option value=""></option>
</select>
</td>
<td>
<select class="form-control" name="opts" required="required">
<option value="">Select Options</option>
<option value="1">Sewn Top (S)</option>
<option value="2">Seal-In-Liner (C)</option>
<option value="">None</option>
</select>
</td>
<td><input class="form-control" type='text' name='cust_code'></td>
<td><input class="form-control" type='text' name='ord_amt' required="required"></td>
</tr>
</tbody>
</table>
<button class="button button-3d button-rounded button-aqua" name="p_order"><i class="icon-repeat"></i>Next Item</button>
<button class="button button-3d button-rounded button-green"><i class="icon-ok"></i>Submit Order</button>
</form>

Add dynamic inputs and insert data to MySQL using PHP

I have a form which has inputs and there is a link called 'Add New Rows' that adds the same row underneath to insert more data if its needed with a remove Row Option. And when i click save button it should save the form with the data already having and the data which i added with Add New Rows. I tried different ways to achieve it, but nothing is working out. Iam putting the form.php page and save.php page.
Form.php is below:
echo "<form name='cart' method='post' class='single' action='price_add_save.php'>";?>
while ($list5 = mysql_fetch_array($result)) {
$slno1++;
echo '<tbody>';
echo '<tr>';
echo "<td width='4%' class='addinput'><a href='#' class='addNew'>Add New</a><input size='1' type='hidden' name='id[$i]' value='{$list5['item_id']}' readonly/><input size='1' type='text' id='sl[$i]' name='sl[$i]' name='sl[$i]' value='{$list5['slno']}' readonly/><input size='1' type='hidden' id='item_id[$i]' name='item_id[$i]' value='{$list5['item_id']}' readonly/></td>";
echo "<td width='4%'><select id='ifmain[$i]' name='ifmain[$i]'><option value='Yes'>Main Item</option><option value='No'>Sub Item</option></select></td>";
echo "<td width='10%' id='addinput'><input type='text' size='15' id='item_name$i' name='item_name[$i]' placeholder='{$list5['item_name']}' value='{$list5['item_name']}'></td>";
echo "<td width='10%'><input type='text' size='7' id='item_partno$i' name='item_partno[$i]' value='{$list5['item_partno']}'></td>";
echo "<td width='15%'><textarea rows='4' cols='50' id='prod_description$i' name='prod_description[$i]'></textarea></td>";
echo "<td width='3%'><input size='1' type='text' name='item_quantity[]' id='item_quantity[]' value='{$list5['item_quantity']}' /></td>";
echo "<td width='3%'><input size='2' type='text' name='item_units[]' id='item_units[]' value='{$list5['item_units']}' readonly/></td>";
echo "<td width='4%'><input size='5' type='text' name='unitprice[]' id='unitprice[]' /></td>";
echo "<td width='8%'><input size='8' type='text' name='total[]' id='total[]' readonly class='total' /></td>";
echo "</tr>";
++$i;
}
echo '<input type="submit" value="--Save Data--" />';
</form>
Save.php is below:
$size = count($_POST['unitprice']);
$i = 0;
while ($i < $size) {
$sl= $_POST['sl'][$i];
$item_id= $_POST['item_id'][$i];
$item_name= $_POST['item_name'][$i];
$prod_description=$_POST['prod_description'][$i];
$prod_description= mysql_real_escape_string($prod_description);
$query = "INSERT INTO comparitive_st_sup SET tender_id='$tender_id', item_id='$item_id', ifmain='$ifmain', slno = '$sl',item_name = '$item_name',item_partno = '$item_partno',prod_description = '$prod_description',sup_itempartno = '$sup_itempartno',currency = '$currency_selected',slab_range= '$slab_range',qty = '$item_quantity',qty_sup = '$item_quantity_sup',item_units = '$item_units',item_units_sup = '$item_units_sup',unitprice = '$unitprice',total = '$total', total_inr='$total_inr', supplier_name='$supplier_name2' ";
mysql_query($query) or die ("Error in query: $query");
++$i;
}
Please find the HTML below:
<html>
<head>
<title>PRICE</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript" type="text/javascript">
tinyMCE.init({
toolbar: false,
menubar: false,
mode: "textareas",
height: "150px",
width: "180px"
});
</script>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
</head>
<body>
<div id="wrapper">
<form name="cart" method="post" class="single" action="price_add_save.php?supplier_name=TE+Connectivity&tender_id=150596">
<div align="center">
<h3>TE Connectivity</h3>
<table style="border-collapse: collapse;" id="table" border="1" cellpadding="2" cellspacing="2" width="100%">
<thead>
<tr bgcolor="#E6E6FA">
<td width="4%">SlNo</td>
<td width="4%">Main Item</td>
<td width="10%">Item Name</td>
<td width="10%">Item Part No</td>
<td width="6%">Part No - Supplier</td>
<td width="4%">Slab Range</td>
<td width="3%">Qty</td>
<td width="4%">Qty Supplier</td>
<td width="3%">Units</td>
<td width="3%">Units Supplier</td>
<td width="4%">Unitprice</td>
<td width="6%">Total</td>
<td width="6%">Currency</td>
<td width="6%">Total INR</td>
</tr>
</thead>
<tbody>
<tr>
<td width="4%">
<input size="1" name="id[0]" value="0" readonly="readonly" type="hidden">
<input size="1" id="sl[0]" name="sl[0]" readonly="readonly" type="text">
<input size="1" id="item_id[0]" name="item_id[0]" value="0" readonly="readonly" type="hidden">
</td>
<td width="4%">
<select id="ifmain[0]" name="ifmain[0]">
<option selected="selected" value="Yes">Main Item</option>
<option value="No">Sub Item</option>
</select>
</td>
<td id="addinput" width="10%">
<input size="15" id="item_name0" name="item_name[0]" placeholder="" type="text">
</td>
<td width="10%">
<input size="7" id="item_partno0" name="item_partno[0]" type="text">
</td>
<td width="6%">
<input size="11" id="sup_itempartno0" name="sup_itempartno[0]" type="text">
</td>
<td width="4%">
<input size="3" class="slab_range" name="slab_range[]" id="slab_range[]" type="text">
</td>
<td width="3%">
<input size="1" data-validation="required" class="item_quantity" name="item_quantity[]" id="item_quantity[]" value="0" type="text">
</td>
<td width="4%">
<input size="1" data-validation="required" class="item_quantity_sup" name="item_quantity_sup[]" id="item_quantity_sup[]" type="text">
</td>
<td width="3%">
<input size="2" class="item_units" name="item_units[]" id="item_units[]" readonly="readonly" type="text">
</td>
<td width="3%">
<input size="2" data-validation="required" class="item_units_sup" name="item_units_sup[]" id="item_units_sup[]" type="text">
</td>
<td width="4%">
<input size="5" data-validation="required" class="unitprice" name="unitprice[]" id="unitprice[]" type="text">
</td>
<td width="8%">
<input size="8" name="total[]" id="total[]" readonly="readonly" class="total" type="text">
</td>
<td width="6%">
<select class="currency-select" data-validation="required" id="currency_change[]" name="currency_change[]">
<option selected="selected" value="">select</option>
<option value="USD" data-price="1">USD</option>
<option value="INR" data-price="67.434191">INR</option>
<option value="GBP" data-price="0.704985">GBP</option>
<option value="EUR" data-price="0.91118">EUR</option>
<option value="SGD" data-price="1.386987">SGD</option>
<option value="AUD" data-price="1.347597">AUD</option>
<option value="CAD" data-price="1.342118">CAD</option>
<option value="CHF" data-price="0.997145">CHF</option>
<option value="JPY" data-price="112.6934">JPY</option>
<option value="MYR" data-price="4.129541">MYR</option>
<option value="ZAR" data-price="15.43258">ZAR</option>
</select>
</td>
<td width="8%">
<input size="8" class="total1" id="total_inr[]" name="total_inr[]" type="text">
</td>
<input class="inrvalue" id="inrvalue" name="inrvalue" value="67.434191" type="hidden">
</tr>
</tbody>
<tbody>
<tr>
<td width="4%">
<input size="1" name="id[1]" value="937" readonly="readonly" type="hidden">
<input size="1" id="sl[1]" name="sl[1]" value="1" readonly="readonly" type="text">
<input size="1" id="item_id[1]" name="item_id[1]" value="937" readonly="readonly" type="hidden">
</td>
<td width="4%">
<select id="ifmain[1]" name="ifmain[1]">
<option selected="selected" value="Yes">Main Item</option>
<option value="No">Sub Item</option>
</select>
</td>
<td id="addinput" width="10%">
<input size="15" id="item_name1" name="item_name[1]" placeholder="Chlorophyll Meter" value="Chlorophyll Meter" type="text">
</td>
<td width="10%">
<input size="7" id="item_partno1" name="item_partno[1]" value=" SPAD 502 DL" type="text">
</td>
<td width="6%">
<input size="11" id="sup_itempartno1" name="sup_itempartno[1]" type="text">
</td>
<td width="4%">
<input size="3" class="slab_range" name="slab_range[]" id="slab_range[]" type="text">
</td>
<td width="3%">
<input size="1" data-validation="required" class="item_quantity" name="item_quantity[]" id="item_quantity[]" value="1" type="text">
</td>
<td width="4%">
<input size="1" data-validation="required" class="item_quantity_sup" name="item_quantity_sup[]" id="item_quantity_sup[]" type="text">
</td>
<td width="3%">
<input size="2" class="item_units" name="item_units[]" id="item_units[]" value="Nos" readonly="readonly" type="text">
</td>
<td width="3%">
<input size="2" data-validation="required" class="item_units_sup" name="item_units_sup[]" id="item_units_sup[]" type="text">
</td>
<td width="4%">
<input size="5" data-validation="required" class="unitprice" name="unitprice[]" id="unitprice[]" type="text">
</td>
<td width="8%">
<input size="8" name="total[]" id="total[]" readonly="readonly" class="total" type="text">
</td>
<td width="6%">
<select class="currency-select" data-validation="required" id="currency_change[]" name="currency_change[]">
<option selected="selected" value="">select</option>
<option value="USD" data-price="1">USD</option>
<option value="INR" data-price="67.434191">INR</option>
<option value="GBP" data-price="0.704985">GBP</option>
<option value="EUR" data-price="0.91118">EUR</option>
<option value="SGD" data-price="1.386987">SGD</option>
<option value="AUD" data-price="1.347597">AUD</option>
<option value="CAD" data-price="1.342118">CAD</option>
<option value="CHF" data-price="0.997145">CHF</option>
<option value="JPY" data-price="112.6934">JPY</option>
<option value="MYR" data-price="4.129541">MYR</option>
<option value="ZAR" data-price="15.43258">ZAR</option>
</select>
</td>
<td width="8%">
<input size="8" class="total1" id="total_inr[]" name="total_inr[]" type="text">
</td>
<input class="inrvalue" id="inrvalue" name="inrvalue" value="67.434191" type="hidden">
</tr>
</tbody>
</table>
</div>
<br>
<br>
<table>
<tbody>
<tr>
<td></td>
<td>
<input value="--Save Data--" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
window.onload = function() {
function calculateRowTotals(row) {
console.log("calculateRowTotals()", row);
var currency = row.find(".currency-select").val();
var conversionRate = row.find(".currency-select option[value=" + currency + "]").data("price");
var totalINR = row.find('.total').val();
//alert (totalINR);
//console.log(totalINR);
//console.log(conversionRate);
console.log("total1 => " + row.find('.total1').length);
//var newTotal = currency==="INR" ? totalINR : (totalINR * conversionRate / row.find('.inrvalue').val()).toFixed(3);
var newTotal = 0;
if (currency === "INR") {
newTotal = totalINR;
} else if (currency === "USD") {
newTotal = ((totalINR * row.find('.inrvalue').val()).toFixed(3));
} else {
newTotal = (((row.find('.inrvalue').val() / conversionRate) * totalINR).toFixed(3));
}
console.log("New total is " + newTotal + " & old one is " + row.find('.total1').val());
row.find('.total1').val(newTotal);
//row.find('.price_unit').val((newTotal/row.find('.qty').val()).toFixed(3));
}
$(document).ready(function() {
//$("select").change(function (event, processing) {
$(".currency-select").change(function(event, processing) {
console.log("A row changed", processing, event);
var row = $(this).closest('tr');
var table = row.closest('table');
var currency = $(this).val();
if (processing) {
// Calculate me
calculateRowTotals($(row));
} else {
// Calculate other if not processing yet
table.find("tr").each(function() {
$(this).find("select").val(currency).trigger("change", 1);
});
}
});
});
}
</script>
<script type="text/javascript">
$('#table :input').change(function() {
var $tr = $(this).closest('tr'),
$totInr = $tr.find('[name="total_inr[]"]'),
unitprice = +$tr.find('[name="unitprice[]"]').val() || 0,
qty = +$tr.find('[name="item_quantity_sup[]"]').val() || 0,
$currency = $tr.find('[name="currency_change[]"] option:selected'),
currency = $currency.val(),
inr = $('#inrvalue').val();
var total = unitprice * qty;
$tr.find('[name="total[]"]').val(total);
})
</script>
</div>
<script type="text/javascript">
$('form#cart').submit(function(e) {
$(this).children('input[type=submit]').attr('disabled', 'disabled');
});
</script>
</body>
</html>

JQuery Onclick display selected info

I want to display the selected price, category and size on the dropdown slideingDiv. But what I have done below is not working. I have try to echo out to see if the data have been sent thought but I got nothing. Is anything wrong with my code?
Script
<script type="text/javascript">
$(document).ready(function () {
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function () {
$(".slidingDiv").slideToggle();
});
});
</script>
Button
<button a href="product.php?ProdID=<?php echo $id; ?>" class="show_hide" id="button" name="button">Add to cart</a></button>
PHP
<?php
dbconnect();
if(isset($_POST['pid']) && isset($_POST['length']) && isset($_POST['Qty']) && `isset($_POST['Category'])){`
$pid = $_POST['pid'];
$length = $_POST["length"];
$qty = $_POST['Qty'];
$Category = $_POST['Category'];
echo $pid; // I have add this echo to see data have been passed though but i get nothing in return
echo $length;
$stmt4 = $conn->prepare("
SELECT Product.Name as ProductName, Category.Name, size, Price
FROM item_Product, Product, Category
WHERE Product.ProdID =:pid
AND size= :length AND Category.Name = :Category Limit 1");
$stmt4->bindParam('pid',$pid);
$stmt4->bindParam('length',$length);
$stmt4->bindParam('Category',$Category);
$stmt4->execute();
foreach ($stmt4->fetchAll(PDO::FETCH_ASSOC) as $row4 ) {
$product_name = $row4["ProductName"];
$price = $row4["Price"];
$length = $row4["size"];
$Category = $row4["Name"];
?>
Item was added shopping bag </br>
Name:<?php echo $row4['ProductName']; ?> </br>
Length:<?php echo $row4['size']; ?> </br>
Category:<?php echo $row4['Name']; ?> </br>
Price:<?php echo $row4['Price']; ?> </br>
<?php } }
?>
View Cart
</div>
TABLE
<td width="160">Price:</td>
echo '<td name="pricetag" id="pricetag">'.$row2['Price'].'</td>';
</tr>
<tr>
<td>Category</td>
<td>
<select id="Category" name="Category">
echo '<option value="'.$row['Name'].'">'.$row['Name'].'</option>';
</select>
</td>
</tr>
<tr>
<td width="160">Length:</td>
<td>
<select name="length" id="length">
<option SELECTED value="'.$row3['size'].'">'.$row3['size'].</option>
</select>
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input type="text" name="Qty" id="Qty" value="1" style="width: 20px; text-align: right" /></td>
</tr>
</table>
<div class="cleaner h20"></div>
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<div class="button">
<button class="show_hide" id="button" name="button">Add to cart</button>
</div>
Try this: SEE MY FIDDLE
HTML
<table>
<tr>
<td>Price</td>
<td>
<select id='priceTag'>
<option value='p1'>price 1</option>
<option value='p2'>price 2</option>
</select>
</td>
</tr>
<tr>
<td>Category</td>
<td>
<select id='Category'>
<option value='c1'>cat 1</option>
<option value='c2'>cat 2</option>
</select>
</td>
</tr>
<tr>
<td>Size</td>
<td>
<select id='Size'>
<option value='s1'>size 1</option>
<option value='s2'>size 2</option>
</select>
</td>
</tr>
</table>
<button id='button'>Submit</button>
<div id='selected'>
<table cellpadding="5" border='1'>
<tr>
<td>Price:</td>
<td id='sprice'></td>
</tr>
<tr>
<td>Category:</td>
<td id='scat'></td>
</tr>
<tr>
<td>Size:</td>
<td id='ssize'></td>
</tr>
</table>
</div>
JQuery
$(document).ready(function()
{
$('#selected').hide();
$('#button').click(function()
{
var price = $('#priceTag').val();
var cat = $('#Category').val();
var size = $('#Size').val();
$('#sprice').text(price);
$('#scat').text(cat);
$('#ssize').text(size);
$('#selected').slideDown();
});
});
Seems that you do not have a space in your <?php} ?>
Do something like <?php } ?>
Error:
<?php} ?>
try this,
<?php } ?> // add space between php and }
<?php}
should be
<?php }
Also
<button a href="product.php?ProdID=<?php echo $id; ?>" class="show_hide" id="button" name="button">Add to cart</a></button> is in correct
should be
<button>Add to cart</button>

Categories