|
|
|
ดึงค่าจาก span tag ให้ tag input บันทึกลงฐานข้อมูล แต่ได้ค่า 0 |
|
|
|
|
|
|
|
ลองconsole.log มาดูก่อนไม่ได้หรอครับ ก่อนจะเอาลงฐานข้อมูล
console.log(span);
จะได้รู้ค่ามันมาจริงมั้ย
|
|
|
|
|
Date :
2023-01-05 10:34:41 |
By :
คนหล่อนิรนาม |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อยากเห็นภาพ ข้อมูลในฟอร์มก่อน submit ครับว่ามีอะไรบ้าง
เพราะโค้ดมันว่างเปล่า ไม่รับค่าใดๆ แสดงว่า span รับค่าจาก javascript ทีหลัง
ดังนั้น
var span = document.getElementById('sum');
var hidden = document.getElementById('hidden_cost');
hidden.value = span.innerHTML;
ต้องเรียกทุกครั้งที่เปลี่ยนค่าใน span ก่อน submit
|
|
|
|
|
Date :
2023-01-05 13:02:10 |
By :
{Cyberman} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอบความคิดเห็นที่ : 2 เขียนโดย : {Cyberman} เมื่อวันที่ 2023-01-05 13:02:10
รายละเอียดของการตอบ ::
... ฟอร์มของหมดทั้งหมดครับ.......
Code (PHP)
<?php include 'tpl_header.php'; ?>
<?php include 'tpl_sidebar.php'; ?>
<?php include 'tpl_topnav.php'; ?>
<?php require_once '../inc/conn.php'; ?>
<script src="../js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="../js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(document).on('keydown', '.ShiptoCode', function() {
var id = this.id;
var splitid = id.split('_');
var index = splitid[1];
$('#' + id).autocomplete({
source: function(request, response) {
$.ajax({
url: "getDetails.php",
type: 'post',
dataType: "json",
data: {
search: request.term,
request: 1
},
success: function(data) {
response(data);
}
});
},
select: function(event, ui) {
$(this).val(ui.item.label); // display the selected text
var custid = ui.item.value; // selected id to input
// AJAX
$.ajax({
url: 'getDetails.php',
type: 'post',
data: {
CustID: custid,
request: 2
},
dataType: 'json',
success: function(response) {
var len = response.length;
if (len > 0) {
var id = response[0]['CustID'];
var CustName = response[0]['CustName'];
var Address = response[0]['Address'];
var CustCode = response[0]['CustCode'];
var District = response[0]['District'];
var Amphur = response[0]['Amphur'];
var Province = response[0]['Province'];
var BrchID = response[0]['BrchID'];
var VATGroupID = response[0]['VATGroupID'];
var SaleAreaID = response[0]['SaleAreaID'];
var VAttype = response[0]['VAttype'];
var ContTel = response[0]['ContTel'];
//var age = response[0]['age'];
var PostCode = response[0]['PostCode'];
var ContTel = response[0]['ContTel'];
var ShiptoCode = response[0]['ShiptoCode'];
var CreditAmnt = response[0]['CreditAmnt'];
var CreditDays = response[0]['CreditDays'];
var EmpID = response[0]['EmpID'];
var ContactName = response[0]['ContactName'];
var ShiptoAddr1 = response[0]['ShiptoAddr1'];
document.getElementById('CustID').value = id;
document.getElementById('CustName').value = CustName;
document.getElementById('CustCode').value = CustCode;
document.getElementById('Address').value = Address;
document.getElementById('District').value = District;
document.getElementById('Amphur').value = Amphur;
document.getElementById('Province').value = Province;
document.getElementById('BrchID').value = BrchID;
document.getElementById('VATGroupID').value = VATGroupID;
document.getElementById('VAttype').value = VAttype;
document.getElementById('ContTel').value = ContTel;
document.getElementById('SaleAreaID').value = SaleAreaID;
document.getElementById('ContTel').value = ContTel;
document.getElementById('ShiptoCode').value = ShiptoCode;
document.getElementById('CreditAmnt').value = CreditAmnt;
document.getElementById('CreditDays').value = CreditDays;
document.getElementById('PostCode').value = PostCode;
document.getElementById('EmpID').value = EmpID;
document.getElementById('ContactName').value = ContactName;
document.getElementById('ShiptoAddr1').value = ShiptoAddr1;
}
}
});
return false;
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$(document).on('keydown', '.GoodName', function() {
var id = this.id;
var splitid = id.split('_');
var index = splitid[1];
$('#' + id).autocomplete({
source: function(request, response) {
$.ajax({
url: "getDetails2.php",
type: 'post',
dataType: "json",
data: {
search: request.term,
request: 1
},
success: function(data) {
response(data);
}
});
},
select: function(event, ui) {
$(this).val(ui.item.label); // display the selected text
var goodid = ui.item.value; // selected id to input
// AJAX
$.ajax({
url: 'getDetails2.php',
type: 'post',
data: {
GoodID: goodid, // $_POST['GoodID]
request: 2
},
dataType: 'json',
success: function(response) {
var len = response.length;
if (len > 0) {
var GoodCode = response[0]['GoodCode'];
var GoodID = response[0]['GoodID'];
var GoodName2 = response[0]['GoodName2'];
var MainGoodUnitID = response[0]['MainGoodUnitID'];
var GoodTypeID = response[0]['GoodTypeID'];
document.getElementById('GoodID_' + index).value = GoodID;
document.getElementById('GoodCode_' + index).value = GoodCode;
document.getElementById('GoodName2_' + index).value = GoodName2;
document.getElementById('MainGoodUnitID_' + index).value = MainGoodUnitID;
document.getElementById('GoodTypeID_' + index).value = GoodTypeID;
}
}
});
return false;
}
});
});
});
</script>
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_left">
<h3><i class="fa fa-newspaper-o"></i> <small>ฟอร์มสั่งซื้อสินค้า</small></h3>
</div>
</div>
<form id="my-form" action="receive_order_save.php" method="post">
<div class="row" style="display: block;">
<div class="col-md-12 col-sm-12 ">
<div class="x_panel">
<div class="x_title">
<h2><i class="fa fa-list-ol"></i><small>ฟอร์มสั่งซื้อสินค้า</small> </h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
</li>
<li><a class="close-link"><i class="fa fa-close"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
<br />
<center>
<h5 style="font-size:20px;font-weight:600;">ฟอร์มสั่งซื้อสินค้า</h5>
</center>
<center>
<h6 style="font-size:18px;">บริษัท มาซา แลบ จำกัด</h6>
</center>
<br>
<br>
<div class="row mb-2">
<div class="col-md-2 col-sm-4 form-group " hidden>
<label for=""><b>วันที่เอกสาร</b> :</label>
<input class="form-control" type="date" value="<?php echo date("Y-m-d"); ?>" id="txtOrderDate" name="DocuDate" hidden>
</div>
<div class="col-md-2 col-sm-12 form-group">
<?php
// $stmt = $conn->prepare("SELECT * FROM SOHD WHERE date_added > NOW() - INTERVAL 1 DAY");
$stmt = $conn->prepare("SELECT TOP 1 * FROM SOHD ORDER BY DocuNo DESC ");
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$date = date("ym"); // select year month
$sub = substr($row['DocuNo'], 7); // cut 7 digit
$doc = $sub + 1;
$docno = sprintf("%05d", $doc);
$stmt = $conn->prepare("SELECT SOID FROM SOHD ORDER BY SOID DESC ");
$stmt->execute();
$so = $stmt->fetch(PDO::FETCH_ASSOC);
$isSO = (int)$so['SOID'];
$isSOID = $isSO + 1;
$stmt = $conn->query("SELECT * FROM EMEmp");
$stmt->execute();
$emp = $stmt->fetchAll();
?>
<label for=""><b>เลขที่เอกสาร</b> :</label>
<input type='text' class=' form-control' id='' value="<?php echo "SO" . $date . "-" . $docno ?>" name="DocuNo">
<input type='hidden' class=' form-control' id='' value="<?php echo $isSOID ?>" name="SOID">
</div>
<div class="col-md-2 col-sm-4 form-group ">
<label for=""><b>PO</b> :</label>
<input class="form-control" type="text" id="" name="CustPONo">
</div>
<div class="col-md-2 col-sm-4 form-group ">
<label for=""><b>วันที่ PO</b> :</label>
<input class="form-control" type="date" value="<?php echo date("Y-m-d"); ?>" id="" name="CustPODate">
</div>
<div class="col-md-2 col-sm-4 form-group ">
<label for=""><b>กำหนดส่งของ</b> :</label>
<input class="form-control" type="date" value="<?php echo date("Y-m-d"); ?>" id="" name="ShipDate">
</div>
<div class="col-md-2 col-sm-4 form-group ">
<label for=""><b>ส่งสินค้าภายใน (วัน)</b> :</label>
<input class="form-control" type="text" id="" name="ValidDays" required="required">
</div>
</div>
<div class="row mb-2">
<div class="col-md-4 col-sm-12 form-group">
<label for=""><b>กรอกข้อมูลลูกค้า</b> :</label>
<input type='text' class='ShiptoCode form-control ' id='CustName' name='CustName' placeholder='ระบุข้อมูลลูกค้า'>
<input type='hidden' class='BrchID form-control' id='BrchID' name="BrchID"> <!-- brchid -->
<input type='hidden' class='VATGroupID form-control' id='VATGroupID' name="VATGroupID"> <!-- VATGroupID -->
<input type='hidden' class='SaleAreaID form-control' id='SaleAreaID' name="SaleAreaID"> <!-- SaleAreaID -->
<input type='hidden' class='VAttype form-control' id='VAttype' name="VatType"> <!-- Vattype -->
<input type='hidden' class='EmpID form-control' id='EmpID' name="EmpID"> <!-- EmpID -->
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>ที่อยู่</b> :</label>
<input type='text' class='Address form-control' id='Address' name="ShipToAddr1">
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>ตำบล</b> :</label>
<input type='text' class='District form-control' id='District' name="District">
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>อำเภอ</b> :</label>
<input type='text' class='Amphur form-control' id='Amphur' name="Amphur">
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>จังหวัด</b> :</label>
<input type='text' class='Province form-control' id='Province' name="Province">
<input type='hidden' class='PostCode form-control' id='PostCode' name="PostCode">
</div>
</div>
<div class="row ">
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>รหัสลูกค้า</b> :</label>
<input type='hidden' class='CustID form-control' id='CustID' name='CustID'>
<input type='text' class='CustCode form-control' id='CustCode' name='CustCode'>
<input type='hidden' class='CustCode form-control' id='ShiptoCode' name='ShiptoCode'>
<input type='hidden' class=' form-control' id='' name='DocuStatus' value='N'> <!-- DocuStatus -->
<input type='hidden' class=' form-control' id='' name='DocuType' value='104'> <!-- DocuType 103-สั่งจอง / 104-สั่งขาย -->
<input type='hidden' class=' form-control' id='' name='GoodType' value='1'> <!-- GoodType -->
<input type='hidden' class=' form-control' id='' name='AppvFlag' value='W'> <!-- AppvFlag -->
<input type='hidden' class=' form-control' id='' name='OnHold' value='N'> <!-- OnHold -->
<input type='hidden' class=' form-control' id='' name='VatRate' value='7'> <!-- VatRate -->
<input type='hidden' class=' form-control' id='' name='InveID' value='1001'> <!-- InveID -->
<input type='hidden' class=' form-control' id='' name='LocaID' value='1002'> <!-- LocalID -->
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>เบอร์โทร</b> :</label>
<input type='text' class='ContTel form-control' id='ContTel' name="Tel">
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>วงเงิน</b> :</label>
<input type='text' class='CreditAmnt form-control ' id='CreditAmnt'>
</div>
<div class="col-md-1 col-sm-12 form-group">
<label for=""><b>เครดิต</b> :</label>
<input type='text' class='CreditDays form-control ' id='CreditDays' name="CreditDays">
</div>
<div class="col-md-2 col-sm-12 form-group">
<label for=""><b>ชื่อผู้ติดต่อ</b> :</label>
<input type='text' class='ContactName form-control' id='ContactName' name="ContactName">
</div>
<div class="col-md-3 col-sm-12 form-group">
<label for=""><b>เลือกขนส่ง</b> :</label>
<select class='form-control' name="TranspID">
<option value='1000'>D.M.K. TRANSPORT</option>
<option value='1001'>INTER EXPRESS </option>
<option value='1002'>UNIVERSAL </option>
<option value='1003'>ขนส่งบริษัทฯ</option>
<option value='1004'>บริษัท ไปรษณีย์ไทย จำกัด(มหาชน)</option>
<option value='1005'>บลู แอนด์ ไว้ท์</option>
<option value='1006'>อื่นๆ (ภายนอก)</option>
</select>
</div>
</div>
<br>
<br>
<h6 style="font-size:18px;"><u>รายละเอียดการสั่งซื้อสินค้า</u></h6>
<br>
<table width="100%" border="1" id="myTable" class="table table-striped jambo_table bulk_action">
<!-- head table -->
<thead>
<tr>
<td>
<div align="center">ค้นหาสินค้า </div>
</td>
<td>
<div align="center">รหัสสินค้า </div>
</td>
<td>
<div align="center">จำนวน </div>
</td>
<td>
<div align="center">ราคา </div>
</td>
<td>
<div align="center">ส่วนลด </div>
</td>
<td>
<div align="center">ส </div>
</td>
<td>
<div align="center">รวม </div >
</td>
</tr>
</thead>
<!-- body dynamic rows -->
<tbody></tbody>
</table>
<h3>ยอดรวม : <span id="sum"></span></h3>
<input type="hidden" id="hidden_cost" name="NetAmnt"/>
<br>
<br />
<input class="btn btn-primary btn-sm" type="button" id="createRows" value="เพิ่มแถว">
<input class="btn btn-danger btn-sm" type="button" id="deleteRows" value="ลบแถว">
<input class="btn btn-warning btn-sm" type="button" id="clearRows" value="ลบแถวทั้งหมด">
<button class="btn btn-secondary btn-sm" type="reset">เคลียร์ข้อมูล</button>
<br>
<br>
<br>
<br>
<center>
<input onclick="return confirm('ยืนยันการบันทึกข้อมูล')" class="btn btn-success btn-lg" type="submit" value="บันทึกข้อมูล" name="submit">
<!-- <button class="btn btn-primary btn-lg" type="reset">Clear</button> -->
</center>
</div>
</div>
</div>
</form>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var rows = 1;
var listno = 0;
$("#createRows").click(function() {
listno++;
var tr = "<tr>";
tr = tr + "<td align='center'><input type='hidden' name='ListNo[]' value='" + listno + "'><input type='text' class='GoodName form-control' name='GoodName[]' id='GoodName_" + rows + "' size='100%'></td>";
tr = tr + "<td align='center'><input type='hidden' name='GoodID[]' id='GoodID_" + rows + "'><input type='text' class='form-control' name='GoodCode[]' id='GoodCode_" + rows + "'><input type='hidden' name='GoodName2[]' id='GoodName2_" + rows + "'><input type='hidden' name='MainGoodUnitID[]' id='MainGoodUnitID_" + rows + "'><input type='hidden' name='GoodTypeID[]' id='GoodTypeID_" + rows + "'></td>";
tr = tr + "<td align='center'><input type='text' class='bc form-control' name='GoodQty2[]' id='' ></td>";
tr = tr + "<td align='center'><input type='text' class='bc form-control' name='GoodPrice2[]' id='' ></td>";
tr = tr + "<td align='center'><input type='text' class='form-control' name='GoodDiscFormula[]' id='ส่วนลด'></td>";
tr = tr + "<td align='center'><input type='text' class='form-control' name='Sumwelfareamnt[]' id='ส'></td>";
tr = tr + "<td align='center'><input type='text' class='form-control' name='GoodAmnt[]' id='รวม'></td>";
tr = tr + "</tr>";
$('#myTable > tbody:last').append(tr);
$('#hdnCount').val(rows);
rows = rows + 1;
});
// delete rows
$("#deleteRows").click(function() {
listno = listno - 1;
if ($("#myTable tr").length != 1) { //tr
$("#myTable tr:last").remove(); //tr
}
});
// create rows
$("#clearRows").click(function() {
rows = 1;
listno = 0;
$('#hdnCount').val(rows);
$('#myTable > tbody:last').empty();
});
// event delegation
$('#myTable').on("keyup", '.bc', function() {
tr = $(this).parent().parent();
qty = parseInt(tr.find("td:nth-of-type(3) input").val());
price = parseInt(tr.find("td:nth-of-type(4) input").val());
// tr.find("td:last input").val(qty * price);
total = parseInt(tr.find("td:nth-of-type(7) input").val(qty*price));
var sum = 0;
$('tr td:last-child').each((index, item) => {
const value = $(item).find('input').val();
if (typeof(value) !== 'undefined' && value !== '') {
sum += parseInt(value);
}
});
$('#sum').text(sum);
});
// var span = document.getElementById('sum');
// var hidden = document.getElementById('hidden_cost');
// hidden.value = span.innerHTML;
// const span = document.getElementById('sum');
// const value = span.innerHTML;
// const input = document.getElementById('hidden_cost');
// input.value = value;
});
</script>
<script>
const span = document.getElementById('sum');
const value = span.innerHTML;
const input = document.getElementById('hidden_cost');
input.value = value;
</script>
</div>
</div>
<!-- /page content -->
<?php include 'tpl_footer.php'; ?>
|
|
|
|
|
Date :
2023-01-06 08:11:56 |
By :
kko |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมแก้ได้แล้วครับ ขอบคุณทุกความเห็นครับ
|
|
|
|
|
Date :
2023-01-06 13:52:30 |
By :
kko |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|