29 lines
1008 B
JavaScript
29 lines
1008 B
JavaScript
const form = document.getElementById('reading-form');
|
|
const inDoor = document.getElementById('inboundDoor');
|
|
const outDoor = document.getElementById('outboundDoor');
|
|
const inTemp = document.getElementById('inboundTemp');
|
|
const outTemp = document.getElementById('outboundTemp');
|
|
const inHum = document.getElementById('inboundHum');
|
|
const outHum = document.getElementById('outboundHum');
|
|
|
|
// Auto-set direction fields (readonly) if you want display
|
|
// omitted here since direction hidden in dual-input
|
|
|
|
form.addEventListener('submit', e => {
|
|
e.preventDefault();
|
|
const payload = {
|
|
inbound: {
|
|
dockDoor: +inDoor.value,
|
|
temperature: +inTemp.value,
|
|
humidity: +inHum.value
|
|
},
|
|
outbound: {
|
|
dockDoor: +outDoor.value,
|
|
temperature: +outTemp.value,
|
|
humidity: +outHum.value
|
|
}
|
|
};
|
|
fetch('/api/readings', {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload)
|
|
}).then(res => res.json()).then(() => form.reset());
|
|
}); |