Table of Contents

2.3.1. Simulated checkboxes

Purpose

Simulated checkboxes are said to be “simulated” because they do not use the default form elements in HTML, namely the <input type=”checkbox”/> fields. They are often used because they are more visually attractive.

Basic HTML code

The basic HTML code uses standard checkboxes:

<form action="index.html" method="post">
	<h2 id="question">Which sports do you play?</h2>
 
	<ul id="answers">
		<li class="choice">
			<label for="golf">
				<input type="checkbox" name="golf" id="golf" />
				Golf
			</label>
		</li>
		<li class="choice">
			<label for="polo">
				<input type="checkbox" name="polo" id="polo" />
				Polo
			</label>
		</li>
		<li class="choice">
			<label for="tennis">
				<input type="checkbox" name="tennis" id="tennis" />
				Tennis
			</label>
		</li>
	</ul>
 
	<input type="submit" value="Submit information" />
</form>

Without JavaScript, a standard form is provided to the user.

Behaviour with JavaScript

The scripts must handle the following points:

The resulting code in JavaScript is as follows:

<form method="post" action="index.html">
    <h2 id="question">Which sports do you play?</h2>
 
    <ul id="answers" role="group" aria-labelledby="question">
        <li class="choice" role="checkbox" aria-checked="false" tabindex="0">
            <img aria-hidden="true" src="images/checkbox-empty.png" alt="unchecked: ">
            Golf            
        </li>
        <li class="choice" role="checkbox" aria-checked="false" tabindex="0">
            <img aria-hidden="true" src="images/checkbox-empty.png" alt="Unchecked : ">
            Polo            
        </li>
        <li class="choice" role="checkbox" aria-checked="false" tabindex="0">
            <img aria-hidden="true" src="images/checkbox-empty.png" alt="Unchecked : ">
            Tennis            
        </li>
    </ul>
 
    <input type="submit" value="Submit information">
</form>

Démonstration