-
-
Save chaiyr/7dffd796b6ac13fce288edd8b3c767e7 to your computer and use it in GitHub Desktop.
ระบบช่วยกรอกข้อมูล จองทะเบียนรถ ที่ https://reserve.dlt.go.th/reserve/s.php (อ่านรายละเอียดที่คอมเมนต์ด้านล่าง)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment