0
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>
<form>
    <label for="cPendrive"><input type="checkbox" name="wyposazenie[]" value="Pendrive" id="cPendrive"/><span>Pendrive</span></label>
</form>

http://jsfiddle.net/4e9tjtL9/

I have problem, then press anything checbox/label always is selected only first checkbox, not checkbox inside form.

Where is problem?

I would like not use javascript and generate random names for atrribute 'for' and 'id'.

2
  • 1
    you have command id's for all checkboxes, change it to classes, ID should be unique. Commented Sep 14, 2014 at 17:40
  • @Mritunjay — The for attribute of a label keys off the id. Commented Sep 14, 2014 at 18:37

1 Answer 1

1

Your HTML is invalid. An id must be unique in a page.

When you click on a label, the browser looks for the element with the matching id. It stops after it is found it (so it always finds the first one).

Make your ids unique.

I would like not use javascript and generate random names for atrribute 'for' and 'id'.

You don't have to use JavaScript (you can use any programming language on the server, or at build time, or you can write them by hand) and the values don't have to be random (a sequential number on the end will do fine).

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, because I thinked, that ID can be that same in form. But is right, that ID must be unique in a page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.