Daniel Robertus
Daniel Robertus

Reputation: 1102

Checking a checkbox didn't work on the second try

I have a form, and when a user uploads a training document it will check the checkbox

$('#training_code_'+trainingCode).attr('checked','checked');

If the user deletes the training it will run this :

$('#training_code_'+trainingCode).removeAttr('checked');

HTML:

<input type="checkbox" value="1" name="training_code_1" id="training_code_1" 
<? if(mysql_num_rows($result_waperd)>0) echo"checked"; ?> disabled="disabled"/>

I tried to:

  1. upload a file and it's checked.
  2. delete the file and it's unchecked.
  3. upload a file again and it still unchecked.

Does anyone know why that happens?

Upvotes: 0

Views: 64

Answers (1)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28528

For DOM properties like checked, disabled and readonly, the proper way to do this (as of JQuery 1.6) is to use prop.

$('#someid').prop('disabled', true);

so try (to check):

$('#training_code_'+trainingCode).prop('checked',true);

uncheck:

$('#training_code_'+trainingCode).prop('checked',false);

Upvotes: 1

Related Questions