tags:

views:

29

answers:

3

Hi folks! I have this loop

for( i=1; i < 65; i++){

  $('#peperszmit1 #tabs-1 #checkBoxHolder').append('<div class="individualCheckbox"><input     type="checkbox" id="checkBoxik'+i+'" name="game1" /> HERE.. </div>');

}

and where it says HERE.. i would like to display value of i . If i just write i inside the div i get 65 checkboxes with "i" next to them. I would like to have a number instead.

Thanks!

A: 
$('#peperszmit1 #tabs-1 #checkBoxHolder').append(' HERE.. ' + i);

should work.

Also, note that $('#peperszmit1 #tabs-1 #checkBoxHolder') means "the single element called checkBoxHolder within the single element called tabs-1 within the single element called peperszmit1 which is rather redundant. If $("#checkBoxHolder') does not specify a single element, you are using IDs wrong.

James Curran
A: 

You need to use the + operator in order to concatenate two strings or a string and variable.

$('#peperszmit1 #tabs-1 #checkBoxHolder')
  .append('<div class="individualCheckbox">' +
          '<input type="checkbox" id="checkBoxik' + i +
                 '" name="game1" /> ' + i + ' </div>');

And your code will also fit to narrow code-boxes like here in SO ;)

galambalazs
+1  A: 
$('#peperszmit1 #tabs-1 #checkBoxHolder').append('<div class="individualCheckbox"><input     type="checkbox" id="checkBoxik'+i+'" name="game1" />' + i + '</div>')

Like this ?

Or did I get your question wrong?

Trefex