|
 |
|
การใส่เงื่อนไขการเรียกใช้ Ajax ลงไปใน Function Add row แบบ element |
|
 |
|
|
 |
 |
|
main dropdown
<?php
include 'dbConfig.php';
$query = $db->query("SELECT * FROM accountcode ORDER BY acc_id ASC ");
$rowCount = $query->num_rows;
?>
<td>
<select id="accountcode" class="accountcode">
<option value=""> - - Please select - - </option>
<?php
if($rowCount > 0){
while($row=$query->fetch_assoc()){
echo '<option value="'.$row['acc_id'].'">'.$row['acc_name'].'</option>';
}
}else{
echo '<option value="">Accountcode not available</option>';
}
?>
</select>
</td>
<td>
<select id="item" class="item">
<option value=""> - - Select accountcode first - -</option>
</select>
Function add row by element Function ที่ใช้เพิ่ม row จากการกดปุ่ม
function fncAdd(){
var tb = document.getElementById('tbl');
var tbody = document.createElement('tbody');
tb.insertBefore(tbody, null);
tr = document.createElement("tr");
tbody.insertBefore(tr, null);
td = document.createElement("td");
var id = document.createTextNode("");
td.insertBefore(id, null);
tr.insertBefore(td, null);
td = document.createElement("td");
var se = document.createElement("select");
se.setAttribute('id','accountcode');
se.options[0] = new Option(" - - Please select - - ","");
se.options[0].selected =1;
td.insertBefore(se, null);
tr.insertBefore(td, null);
td = document.createElement("td");
se = document.createElement("select");
se.setAttribute('id','item');
se.options[0] = new Option(" - - Select accountcode first - - ","");
se.options[0].selected =1;
td.insertBefore(se, null);
tr.insertBefore(td, null);
tb.appendChild(tbody);
ตัวโค้ดตัวแรกเป็นตัวตั้งต้นนะครับพอทำการกดปุ่ม ADD ฟังก์ชัน fncAdd ก็จะทำงานและเพิ่มตัว select มาจากในฟังก์ชันนั้นแทนปัญหาคือผมใส่ เงื่อนไขการคอล Ajax ลงไปใน fncAdd ไม่ได้ครับ ทำให้ตอนกดปุ่ม select ที่ได้ออกมาเป็น select เปล่าๆครับ ต้องแก้หรือเขียนอย่างไรช่วยแนะนำทีครับขอบคุณครับ
Tag : PHP, MySQL, JavaScript, Ajax

|
ประวัติการแก้ไข 2019-06-28 15:38:41 2019-06-28 15:39:15
|
 |
 |
 |
 |
Date :
2019-06-28 15:37:54 |
By :
2246598742088718 |
View :
911 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใน function addrow ให้เปลี่ยนค่า id ของ element ครับ
เช่น
id_1
id_2
id_3
..
|
 |
 |
 |
 |
Date :
2019-07-01 10:11:02 |
By :
mongkon.k |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|