DLT_applyFields({ id: '1122334455667', prefix: 'นาย', // ต้องสะกดให้เหมือนตัวเลือกใน dropdown เป้ะๆ name: 'ธนารัตน์', lname: 'นักจองทะเบียน', phone: '0812345678', brand: 'LAMBORGHINI', // ต้องสะกดให้เหมือนตัวเลือกใน dropdown เป้ะๆ cassis: 'MR1234567890', number: '999' // แนะนำให้แก้โค้ดส่วนนี้ ปรับให้อ่านค่าจาก localStorage จะได้ไม่ต้องรันเลขเองด้วยมือทุกครั้ง }); function DLT_applyFields(data) { isbody = 999; // bypass validation const fields = document.querySelectorAll('input,select') let f = { number: document.querySelector('#number') }; let n = [18,19,20,21,22,23,24]; for(i = 18; i <= 24; i++){ // prefix, name, lastname if(fields[i].id === 'prefixZQ'){ f.prefix = fields[i]; f.name = fields[i+1]; f.lname = fields[i+2]; let index = n.indexOf(i); if (index !== -1) { n.splice(index, 3); } } // brand if(fields[i].tagName === 'SELECT' && fields[i].id !== 'prefixZQ'){ f.brand = fields[i]; let index = n.indexOf(i); if (index !== -1) { n.splice(index, 1); } } // phone number if(fields[i].onkeypress != null && fields[i].onkeypress.toString() == 'function onkeypress(event) {\ncheck_number()\n}'){ f.phone = fields[i]; let index = n.indexOf(i); if (index !== -1) { n.splice(index, 1); } } // cassis number if(fields[i].onkeypress != null && fields[i].onkeypress.toString() == 'function onkeypress(event) {\ncheck_number1()\n}'){ f.cassis = fields[i]; let index = n.indexOf(i); if (index !== -1) { n.splice(index, 1); } } } console.log(n, fields) f.id = fields[n.shift()]; // id card //apply data if provided Object.keys(data).forEach(i=>{ f[i].value = data[i]; }) return f; // return all fields in case you need it }