2

i'm trying to add a list of checkbox dynamically but it does not show properly with mobile style.

here the js code:

var name = "option";
var id = "id";

$("#frame").html('<fieldset data-role="controlgroup"><legend>Seleziona le categorie da eliminare:</legend></fieldset>');

for (var i = 0; i < 4; i++) {
  $("fieldset").append('<input type="checkbox" name="' + name + '" id="' + id + '"><label for="' + name + '">' + name + '</label>');
}

$("#frame").append('<a href="#" data-role="button" data-inline="true" id="btndelcat">Elimina</a>');

$("#frame").trigger('create');

Code on editor JSFiddle.

1 Answer 1

3

You have a mistake in creating checkboxes. Label's for attribute should match checkbox's id.

From this:

$("fieldset").append('<input type="checkbox" name="' + name + '" id="' + id + '"><label for="' + name + '">' + name + '</label>');

To this:

$("fieldset").append('<input type="checkbox" name="' + name + '" id="id' + i + '"><label for="id' + i + '">' + name + '</label>');

Demo

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

Comments

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.