The rows are getting added in upper table only even though table id is different
The functionality shpuld work as I have included different ID for different table
Please heklpme to identify the error
THE JS is below
$(document).ready(function () {
$('#myTable').on('click', 'input[type="button"]', function () {
$(this).closest('tr').remove();
});
$('p input[type="button"]').click(function () {
$('#myTable').append('<tr><td><input type="text" class="form-control" name="aname[]" value="" placeholder="Input Name" /> </td><td><input type="amount" class="form-control" name="aamount[]" value="" placeholder="Input Value" /></td><td><input type="number" class="form-control" name="apriority[]" value="" placeholder="Input Value" /></td><td><input type="button" class ="btn btn-danger" value="x Delete" /></td></tr>')
});
$('#myTable1').on('click', 'input[type="button"]', function () {
$(this).closest('tr').remove();
});
$('p input[type="button"]').click(function () {
$('#myTable1').append('<tr><td><input type="text" class="form-control" name="dname[]" value="" placeholder="Input Name" /> </td><td><input type="amount" class="form-control" name="damount[]" value="" placeholder="Input Value" /></td><td><input type="number" class="form-control" name="dpriority[]" value="" placeholder="Input Value" /></td><td><input type="button" class ="btn btn-danger" value="x Delete" /></td></tr>')
});
});
Below is HTML
<div class="form-group">
<label for="grade">Grade</label>
<select class="form-control required alphanum" name="grade" id="grade" required>
<option value="">Please select...</option>
<?php fetch_grade($conn);
?>
</select>
</div>
<div class="form-group">
<label for="name">Basic Salary</label>
<input type="text" name="basic" id="basic" class="form-control" />
</div>
<div class="form-group">
<label for="overtime">Overtime Rate(Per Hour)</label>
<input type="text" name="overtime" id="overtime" class="form-control" />
</div>
Allowances
<br>
<p> <input type="button" class="btn btn-primary" value="+ Add Allowance"></p>
<table id="myTable" class="table table-condensed table-hover table-bordered table-hover table-responsive table-striped">
<thead>
<tr>
<th>Allowance Name</th>
<th>Amount</th>
<th>Display Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="form-control" name="aname[]" value="" placeholder="Input Name" /> </td>
<td><input type="amount" class="form-control" name="aamount[]" value="" placeholder="Input Value" /></td>
<td><input type="number" class="form-control" name="apriority[]" value="" placeholder="Input Value" /></td>
<td><input type="button" class ="btn btn-danger" value="x Delete" /></td>
</tr>
</tbody>
</table>
Deductions
<p> <input type="button" class="btn btn-primary" value="+ Add Deduction"></p>
<table id="myTable1" class="table table-condensed table-hover table-bordered table-hover table-responsive table-striped">
<thead>
<tr>
<th>Deduction Name</th>
<th>Amount</th>
<th>Display Priority</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="form-control" name="dname[]" value="" placeholder="Input Name" /> </td>
<td><input type="amount" class="form-control" name="damount[]" value="" placeholder="Input Value" /></td>
<td><input type="number" class="form-control" name="dpriority[]" value="" placeholder="Input Value" /></td>
<td><input type="button" class ="btn btn-danger" value="x Delete" /></td>
</tr>
</tbody>
</table>
I am not sure where I am going wrong? I have searched various forum but didnt come with accurate solutions and was wonderingif someone canthrow light on this and how can I optmisie it
This selector bind some function twice:
$('p input[type="button"]')
which means it will only run for one table.
Add some class to the <p> element
<p class="btnMyTable"> <input type="button"
<p class="btnMyTable1"> <input type="button"
And bind to it:
$('p.btnMyTable input[type="button"]')
$('p.btnMyTable1 input[type="button"]')
Related
Submit to Database Success But Value Of Debit And Kredit are 0 and 1
<table>
<tr>
<td>
<input class="form-control" name="debit[]" type="text" placeholder="Debit" autocomplete="off" required />
</td>
<td>
<input class="form-control" name="Kredit[]" type="text" placeholder="Kredit" autocomplete="off" required />
</td>
</tr>
<tr>
<th>Total</th>
<th colspan="2">
<input class="form-control" name="total" type="text" jAutoCalc="{debit[]} + {kredit[]}" />
</th>
</table>
This is the error i receive
Parsing error:unrecognied value
(Error:valueNotParsed):<*>{debit[]}+{kredit[]}
I have my edit.blade.php file as below mentioned
<table class="table">
<thead>
<tr>
<th>Vendor</th>
<th>Item</th>
<th>Qty</th>
<th>Rate</th>
<th>Total</th>
<th>Description</th>
<th>Job No</th>
</tr>
</thead>
<tbody>
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
<td><input type="text" class="form-control" name="item_name[]" id="item_name" value="{{$po_item->cost_item->item->name}}" readonly></td>
<td><input type="text" class="form-control" name="qty[]" id="qty" value="{{$po_item->qty}}"></td>
<td><input type="text" class="form-control" name="rate[]" id="rate" value="{{$po_item->rate}}"></td>
<td><input type="text" class="form-control" name="total[]" id="total" value="{{$po_item->qty * $po_item->rate}}"></td>
<td><input type="text" class="form-control" name="description[]" id="description" value="{{$po_item->description}}"></td>
<td><input type="text" class="form-control" name="job_id[]" id="job_id" value="{{$po_item->cost_item->job_id}}" readonly></td>
<td>
<form action="{{action('Employee\POItemController#destroy', $po_item->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<form action="{{ route('employee.poitem.update', $vendor_company_id )}}" method="post">
{{csrf_field()}}
{{method_field('PATCH')}}
#foreach ($po_items as $po_item)
<input type="hidden" name="cost_item_id[]" value="?">
<input type="hidden" name="qty[]" value="?">
<input type="hidden" name="rate[]" value="?">
<input type="hidden" name="description[]" value="?">
#endforeach
<button type="submit" class="btn btn-primary">Update</button>
</form>
Since there are two forms in the same page, i find it hard to pass new form values to the update function. I read on using the same session to solve this issue, but it wasn't clear enough for me to proceed with it
Instead of Making delete form you can do it with anchor tag. I don't know it is correct way or not but it works fine.
Delete
Hope this helps :)
Your input id values are incorrect. In HTML, an id should be unique across all HTML tags. When you make a foreach :
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
</tr>
#endforeach
you're assigning all inputs vendor_name to same id="vendor_name, which is W3C incorrect. You could use instead
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name_{{$po_item->id}}" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
</tr>
#endforeach
But that's not the real problem here, you need upon submitting the UPDATE Form to read each input data and pushes it in hidden inputs.
Do you use vanilla Javascript or JQuery? With JQuery you can achieve it easier, you must put some scripts on the page that contains the forms. The idea is to find each input value for like qty, push them into array and convert that array to JSON string and put that JSON string as value to hidden qty input. Try this codes :
<table class="table">
<thead>
<tr>
<th>Vendor</th>
<th>Item</th>
<th>Qty</th>
<th>Rate</th>
<th>Total</th>
<th>Description</th>
<th>Job No</th>
</tr>
</thead>
<tbody id="table_inputs">
#foreach ($po_items as $po_item)
<tr>
<td><input type="text" class="form-control" name="vendor_name[]" id="vendor_name_{{$po_item->id}}" value="{{$po_item->cost_item->vendor_company->name}}" readonly></td>
<td><input type="text" class="form-control" name="item_name[]" id="item_name_{{$po_item->id}}" value="{{$po_item->cost_item->item->name}}" readonly></td>
<td><input type="text" class="form-control" name="qty[]" id="qty_{{$po_item->id}}" value="{{$po_item->qty}}"></td>
<td><input type="text" class="form-control" name="rate[]" id="rate_{{$po_item->id}}" value="{{$po_item->rate}}"></td>
<td><input type="text" class="form-control" name="total[]" id="total_{{$po_item->id}}" value="{{$po_item->qty * $po_item->rate}}"></td>
<td><input type="text" class="form-control" name="description[]" id="description_{{$po_item->id}}" value="{{$po_item->description}}"></td>
<td><input type="text" class="form-control" name="job_id[]" id="job_id_{{$po_item->id}}" value="{{$po_item->cost_item->job_id}}" readonly></td>
<td>
<form action="{{action('Employee\POItemController#destroy', $po_item->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<form id="form_update_poitem" action="{{ route('employee.poitem.update', $vendor_company_id )}}" method="post">
{{csrf_field()}}
{{method_field('PATCH')}}
#foreach ($po_items as $po_item)
<input type="hidden" name="cost_item_id[]" >
<input type="hidden" name="qty[]" >
<input type="hidden" name="rate[]" >
<input type="hidden" name="description[]" >
#endforeach
<button type="submit" class="btn btn-primary">Update</button>
</form>
<script>
$(document).ready(function() {
console.log('document is ready, proceed to form update codes');
// find button form
var button = $('#form_update_poitem button');
// add onclick event
button.on('click', function(e){
// find input array input values, turn them into array and pass that array to Hidden Input array
var itemArr = [];
$("#table_inputs input[type='item_name']").each(function(){
itemArr.push($(this).val());
});
console.log(itemArr);
$("#form_update_poitem input[type='cost_item_name']").val(JSON.stringify(itemArr));
var qtyArr = [];
$("#table_inputs input[type='qty']").each(function(){
qtyArr.push($(this).val());
});
console.log(qtyArr);
$("#form_update_poitem input[type='qty']").val(JSON.stringify(qtyArr));
var rateArr = [];
$("#table_inputs input[type='rate']").each(function(){
rateArr.push($(this).val());
});
console.log(rateArr);
$("#form_update_poitem input[type='rate']").val(JSON.stringify(rateArr));
var descriptionArr = [];
$("#table_inputs input[type='description']").each(function(){
descriptionArr.push($(this).val());
});
console.log(descriptionArr);
$("#form_update_poitem input[type='description']").val(JSON.stringify(descriptionArr));
});
});
</script>
<div class="col-xs-12 col-md-10" style="padding:0px 100px 0px 50px; color:blue;">
<form action="#" style="color:blue;" method="POST" >
<div class="well well-sm" >
<table border="collapse; border-spacing:5px;" style="background-color:pink;">
<thead>
<th>Stock ID</th>
<th>Medicine Name</th>
<th>Quantity Unit</th>
<th>Unit Price</th>
<th>Selling Price</th>
<th>Sold Quantity</th>
<th>Total Price</th>
<th><input type="button" value="+" id="add" class="btn btn-primary"></th>
</thead>
<tbody class="detail">
<tr>
<td><input type="text" class="form-control" id="si" name="si"></td>
<td><input type="text" class="form-control" id="mn" name="mn" value="<?php
include_once('classes/class.select.php');
$bill = new select();
$value = $bill ->billing($_POST['si']);
foreach($value as $row){
echo $row["medi_name"];
}
?>"></td>
<td><input type="text" class="form-control" id="qu" name="qu" value="<?php echo $row["quantity_unit"];?>"></td>
<td>
<input type="text" class="form-control" id="up" name="up" value="<?php echo $row["unit_price"]; ?>"></td>
<td>
<input type="text" class="form-control" id="sp" name="sp" value="<?php echo $row["selling_price"];?>"></td>
<td><input type="text" class="form-control" id="t" name="t" ></td>
<td><input type="text" class="form-control" id="ls" name="ls" ></td>
<td><input type="submit" class="btn btn-success" value="Bill" name="savesel"><br></td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
This is my table of billing system of medicine. When we give stock Id, the other columns are automatically fill according to relevant stock Id. I want to add some more rows to this table like this. But when I click on bill button on second row, whole row will be disappeared. I also want to calculate whole total price of the end.
<script>
function addnew(){
var n=($('.detail tr').length-0)+1;
var tr =
'<tr>' +
'<td><input type="text" class="form-control" id="si" name="si"></td>'+
'<td><input type="text" class="form-control" id="mn" name="mn" value="<?php
include_once('classes/class.select.php');
$bill = new select();
$value = $bill ->billing($_POST['si']);
foreach($value as $row){
echo $row["medi_name"];
}
?>"></td>'+
'<td><input type="text" class="form-control" id="qu" name="qu" value=["quantity_unit"]></td>'+
'<td><input type="text" class="form-control" id="up" name="up" value=["unit_price"]></td>'+
'<td><input type="text" class="form-control" id="sp" name="sp" value=["selling_price"]></td>'+
'<td><input type="text" class="form-control" id="t" name="t" ></td>'+
'<td><input type="text" class="form-control" id="ls" name="ls" ></td>'+
'<td><input type="submit" class="btn btn-success" value="Bill" name="savesel"><br></td>'+
'</tr>';
$('.detail').append(tr);
}
$(function(){
$('#add').click(function(){
addnew();
});
});
</script>
$("#cloneTable tfoot #addNew").on("click", function() {
var clonedRow = $('#cloneTable tbody tr:first').clone();
clonedRow.find('input').val('');
$('#cloneTable tbody').append(clonedRow) ;
});
This is my table. I am developing billing application in core php mysql. Each row insert into table means need more memory, so I need to insert an one customer bill in a single row with all values separated by comma,
<table id="options-table" border="1">
<tbody><tr>
<th>S.NO</th>
<th>Product Name</th>
<th>Qty</th>
<th>Rate ($)</th>
<th>Total ($)</th>
<th>Option</th>
</tr>
<tr>
<td><span id="snum">1.</span></td>
<td><input type="text" name="productname[]" required="" class="ui-wizard-content valid"></td>
<!--<td><input type="text" style="width:80px;" name="itemcode" /></td> -->
<td><input type="text" class="qty ui-wizard-content valid" name="qty[]" required=""></td>
<td><input type="text" class="rate ui-wizard-content valid" name="rate[]" required=""></td>
<td><input type="text" class="tcost ui-wizard-content valid" name="tcost[]" readonly=""></td>
<td><input type="button" class="del btn-danger ui-wizard-content" value="Delete"></td>
</tr>
<tr>
<td><span id="snum">2.</span></td>
<td><input type="text" name="productname[]" required="" class="ui-wizard-content valid"></td>
<!--<td><input type="text" style="width:80px;" name="itemcode" /></td> -->
<td><input type="text" class="qty ui-wizard-content valid" name="qty[]" required=""></td>
<td><input type="text" class="rate ui-wizard-content valid" name="rate[]" required=""></td>
<td><input type="text" class="tcost ui-wizard-content" name="tcost[]" readonly=""></td>
<td><input type="button" class="del btn-danger" value="Delete"></td>
</tr><tr><td><span id="snum3">3.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td> <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost" name="tcost[]" readonly=""></td><td><input type="button" class="del btn-danger" value="Delete"></td></tr><tr><td><span id="snum3">4.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td> <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost" name="tcost[]" readonly=""></td><td><input type="button" class="del btn-danger" value="Delete"></td></tr><tr><td><span id="snum3">6.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td> <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost valid" name="tcost[]" readonly=""></td><td><input type="button" class="add btn-success" value="Add More"></td></tr>
</tbody></table>
In the above table array values are insert into single row, PRODUCT NAME are separated with comma(,) same as QTY, RATE and TOTAL, can you suggest me.
Table structure:
S.NO Product Name Qty Rate ($) Total ($)
1. flowers 5 5 35
2. jasmine 6 5 30
3. rose 10 8 80
4. marigold 15 9 135
6.
This is example one , i tried this code work fine.
<?php
include 'connection/db_connection.php';
if(isset($_REQUEST['save'])) {
$product_name = implode(",", $_REQUEST["product"]);
print $product_name;
}
$query="insert into product (product_name) values('".$product_name."')";
$sql=mysql_query($query);
if($sql)
echo "success";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form name="myform" method="post">
<input type="text" name="product[]" value="rose">
<input type="text" name="product[]" value="garlands">
<input type="text" name="product[]" value="marigold">
<input type="text" name="product[]" value="jasmine">
<input type="text" name="product[]" value="jasmine garlands">
<input type="submit" name="save" value="Save">
</form>
</body>
</html>
I have 2 forms in a page, but basically the form action, method and fields name are the same. I have made these two forms because one form is for desktop and the other is for a mobile screen. I am just hiding one form when it is a desktop screen and not a mobile screen. When I am using post, in the next page it is showing me a null value. I am not getting any post value. Can anyone suggest why this is happening?
/* for dekstop*/
<div class="LregisterI"><br><div class="close"><img src="<?=$img_loc?>close.png" id="btnClose"/> </div>
<div class="Lregister">
<form action="line_check.php" class="form" name="reg" method="POST" >
<table border="0" align="center" width="" style="">
<tr>
<td colspan="4">
<img src="<?=$img_loc?>regi.png" />
</td>
</tr>
<tr>
<td align="" width="78">Name</td>
<td>
<input type="text" id="name" name="name" value="" onfocus="document.getElementsByClassName('err1')[0].innerHTML=''" class="inputstyle h" />
</td>
<td align="center">Gender</td>
<td>
<div class="gender">
<div class="umale">
<input type="radio" name="gender" checked value="Male">
<label>Male</label>
</div>
<div class="ufemale">
<input type="radio" name="gender" value="Female">
<label>Female</label>
</div>
</div>
</td>
</tr>
<tr>
<td align="" width="78"></td>
<td height="10">
<div class="err err1" id="err1"></div>
</td>
<td align="center"></td>
<td>
<div></div>
</td>
</tr>
<tr>
<td colspan="4">
<div class="hline"></div>
</td>
</tr>
<tr>
<td height="10" colspan="4"></td>
</tr>
<tr>
<td align="">Password</td>
<td>
<input type="password" id="pword" name="pword" value="" onfocus="document.getElementsByClassName('err2')[0].innerHTML=''" class="inputstyle" />
</td>
<td align="center">Confirm Password</td>
<td>
<input type="password" id="spword" name="spword" value="" onfocus="document.getElementsByClassName('err3')[0].innerHTML=''" value="" class="inputstyle" />
</td>
</tr>
<tr>
<td align="" width="78"></td>
<td height="20">
<div class="err err2" id=""></div>
</td>
<td align="center"></td>
<td>
<div class="err err3" id=""></div>
</td>
</tr>
<tr>
<td align="">Email</td>
<td>
<input type="text" id="email" name="email" onfocus="document.getElementsByClassName('err4')[0].innerHTML=''" class="inputstyle" />
</td>
<td align="center">Collage</td>
<td>
<input type="text" id="college" name="college" onfocus="document.getElementsByClassName('err5')[0].innerHTML=''" value="" class="inputstyle" />
</td>
</tr>
<tr>
<td align="" width="78"></td>
<td height="20">
<div class="err err4" id=""></div>
</td>
<td align="center"></td>
<td>
<div class="err err5" id=""></div>
</td>
</tr>
<tr>
<td align="">Mobile</td>
<td>
<input type="hidden" name="reg" value="register">
<input type="text" id="no" name="number" value="" onfocus="document.getElementsByClassName('err6')[0].innerHTML=''" class="inputstyle" />
</td>
<td align="center">City</td>
<td>
<input type="text" id="city" name="city" value="" onfocus="document.getElementsByClassName('err7')[0].innerHTML=''" class="inputstyle" />
</td>
</tr>
<tr>
<td align="" width="78"></td>
<td height="10">
<div class="err err6" id=""></div>
</td>
<td align="center"></td>
<td>
<div class="err err7" id=""></div>
</td>
</tr>
<tr>
<td align="" width="78"></td>
<td colspan="3">
<input type="button" name="sub1" class="submit" value="" onclick="chk();" />
</td>
</tr>
</table>
</form>
</div>
/* for Mobile*/
<div class="LregisterS">
<form action="line_check.php" class="form" name="reg" method="POST" >
<img src="./static/img/regi.png" height="43">
<div class="name">
<div class="fl">Name</div>
<input type="text" id="name" name="name" onfocus="document.getElementsByClassName('err1')[1].innerHTML=''" class="inputstyle h fr" />
</div>
<div class="err1 mT er " id=""></div>
<div class="name" >
<div class="fl" style="width:186px;">Gender</div>
<div class="umale fr"><input type="radio" name="gender" checked value="Male" class="umaleI" /><label>Male</label></div>
<div class="ufemale fr" ><input type="radio" name="gender" value="Female" class="ufemaleI" /> <label>Female</label></div>
</div>
<div class="email">
<div class="fl">Password</div>
<input type="password" id="pword" name="pword" value="" onfocus="document.getElementsByClassName('err2')[1].innerHTML=''" class="inputstyle h fr" />
</div>
<div class="err2 mT er " id=""></div>
<div class="mobile">
<div class="fl">Confirm Password</div>
<input type="password" id="spword" name="spword" value="" onfocus="document.getElementsByClassName('err3')[1].innerHTML=''" class="inputstyle h fr" />
</div>
<div class="err3 mT er " id=""></div>
<div class="email">
<div class="fl">Email</div>
<input type="hidden" name="reg" value="register">
<input type="text" id="email" name="email" onfocus="document.getElementsByClassName('err4')[1].innerHTML=''" class="inputstyle h fr" />
</div>
<div class="err4 mT er" id=""></div>
<div class="mobile">
<div class="fl">Collage</div>
<input type="text" id="college" name="college" onfocus="document.getElementsByClassName('err5')[1].innerHTML=''" class="inputstyle h fr" />
</div>
<div class="err5 mT er" id=""></div>
<div class="mobile">
<div class="fl">Mobile</div>
<input type="text" id="no" name="number" value="" onfocus="document.getElementsByClassName('err6')[1].innerHTML=''" value="" class="inputstyle h fr" />
</div>
<div class="err6 mT er " id=""></div>
<div class="mobile">
<div class="fl">City</div>
<input type="text" id="city" name="city" value="" onfocus="document.getElementsByClassName('err7')[1].innerHTML=''" value="" class="inputstyle h fr" />
</div>
<div class="err7 mT er " id=""></div>
<div class="sub"><input type="button" name="sub" class="submit" value="" onclick="chk();" /></div>
</form>
</div>
</div>
I think for this purpose you need to use $_SERVER['HTTP_USER_AGENT'] function in php. Use it and check if it is from pc or from the mobiel