ဖျောက်ထားတဲ့ Input (type="hidden")
HTML Living Standard
Field မပေါ်ဘဲ form နဲ့အတူ တန်ဖိုးပို့ဖို့ သုံးပါတယ်။ Browser ထဲမှာ အသုံးပြုသူက တန်ဖိုးကို ကြည့်နိုင်၊ ပြင်နိုင်ပါတယ်။
Code စမ်းလို့ရတဲ့ သင်ခန်းစာ ဖွင့်ရန်
ဒီစာမျက်နှာမှာ
Attribute နဲ့ အလုပ်လုပ်ပုံ
| တန်ဖိုး သို့မဟုတ် ရေးပုံ | အလုပ်လုပ်ပုံ |
|---|---|
name="workshop-id" | Form data ထဲက တန်ဖိုးအတွက် နာမည် သတ်မှတ်ပါတယ်။ |
value="web-101" | ဒီနာမည်နဲ့ တွဲပို့မယ့် တန်ဖိုးပါ။ |
နမူနာကို စမ်းကြည့်ပါ
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hidden input</title>
<style>
form { display: grid; gap: 12px; justify-items: start; } output { display: block; margin-top: 10px; }
</style>
</head>
<body>
<form id="demo">
<p>The workshop code is included with the form.</p>
<input type="hidden" name="workshop-id" value="web-101">
<button type="submit">Check</button>
</form>
<output id="response"></output>
<script>
const form = document.querySelector('#demo');
form.addEventListener('click', event => {
const submitter = event.target.closest('[type="submit"], [type="image"]');
if (!submitter) return;
event.preventDefault();
if (!form.noValidate && !submitter.formNoValidate && !form.reportValidity()) return;
const values = new FormData(form, submitter);
document.querySelector('#response').textContent =
'Passed validation. Fields received: ' + [...values.keys()].join(', ');
});
</script>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ Field မမြင်ရပေမယ့် Check နှိပ်ရင် ပို့လိုက်တဲ့ field နာမည်တွေထဲ workshop-id ပါပါတယ်။