ช่องทำเครื่องหมายจะใช้เมื่อต้องเลือกมากกว่าหนึ่งตัวเลือก
ต่อไปนี้เป็นตัวอย่าง HTML code, CheckBox.htm สำหรับแบบฟอร์มที่มีช่องทำเครื่องหมายสองช่อง
<html> <body> <form action = "main.jsp" method = "POST" target = "_blank"> <input type = "checkbox" name = "maths" checked = "checked" /> Maths <input type = "checkbox" name = "physics" /> Physics <input type = "checkbox" name = "chemistry" checked = "checked" /> Chemistry <input type = "submit" value = "Select Subject" /> </form> </body> </html>
รหัสข้างต้นจะสร้างผลลัพธ์ดังต่อไปนี้ -
ต่อไปนี้เป็นโปรแกรม main.jsp JSP สำหรับจัดการอินพุตที่กำหนดโดยเว็บเบราว์เซอร์สำหรับปุ่มช่องทำเครื่องหมาย
<html>
<head>
<title>Reading Checkbox Data</title>
</head>
<body>
<h1>Reading Checkbox Data</h1>
<ul>
<li><p><b>Maths Flag:</b>
<%= request.getParameter("maths")%>
</p></li>
<li><p><b>Physics Flag:</b>
<%= request.getParameter("physics")%>
</p></li>
<li><p><b>Chemistry Flag:</b>
<%= request.getParameter("chemistry")%>
</p></li>
</ul>
</body>
</html> โปรแกรมข้างต้นจะสร้างผลลัพธ์ดังต่อไปนี้ -
การอ่านข้อมูลช่องทำเครื่องหมาย
-
ธงคณิตศาสตร์ : :บน
-
ธงฟิสิกส์: :null
-
ธงเคมี: :บน