filledat
filledat

Reputation: 47

image-Checkboxes aren t working

I have 3 picture-checkboxes. With this code: Codepen 1 they looked like I want them.

In the next step I added the form: Codepen 2

Now you see - the form is creating 3 own checkboxes instead of using the picture. Can you help me please?

Upvotes: 2

Views: 84

Answers (1)

Saurav Rastogi
Saurav Rastogi

Reputation: 9731

Change your <option>'s id to <label>'s for attribute (in your case use cb1, cb2 & cb3 in <option>'s id attribute), just like:

<li>
  <input type="checkbox" id="cb1" value="1" />
  <label for="cb1"><img src="http://betailor.de/wp-content/uploads/2016/12/engern.png" /></label>
</li>

Have a look at the working snippet below:

ul {
  list-style-type: none;
}

li {
  display: inline-block;
}

input[type="checkbox"][id^="cb"] {
  display: none;
}

label {
  border: 1px solid #fff;
  padding: 10px;
  display: block;
  position: relative;
  margin: 10px;
  cursor: pointer;
}

label:before {
  background-color: white;
  color: white;
  content: " ";
  display: block;
  border-radius: 50%;
  border: 1px solid grey;
  position: absolute;
  top: -5px;
  left: -5px;
  width: 25px;
  height: 25px;
  text-align: center;
  line-height: 28px;
  transition-duration: 0.4s;
  transform: scale(0);
}

label img {
  height: 49px;
  width: 122px;
  transition-duration: 0.2s;
  transform-origin: 50% 50%;
}

:checked + label {
  border-color: #ddd;
}

:checked + label:before {
  content: "✓";
  background-color: green;
  transform: scale(1);
}

:checked + label img {
  transform: scale(0.9);
  box-shadow: 0 0 5px #333;
  z-index: -1;
}
<form method="post" action="processform.php">
<ul>
  <li><input type="checkbox" id="cb1" value="1" />
    <label for="cb1"><img src="http://betailor.de/wp-content/uploads/2016/12/engern.png" /></label>
  </li>
  <li><input type="checkbox" id="cb2" value="1" />
    <label for="cb2"><img src="http://betailor.de/wp-content/uploads/2016/12/Kürzen.png" /></label>
  </li>
  <li><input type="checkbox" id="cb3" value="1" />
    <label for="cb3"><img src="http://betailor.de/wp-content/uploads/2016/12/reapieren.png" /></label>
  </li>
</ul>
<input type="submit" name="send" value="Submit" />
</p>
</form>

Hope this helps!

Upvotes: 2

Related Questions