[SOLVED] update checkbox after dropdown selection

Hi all,

i can’t figure how to do that :

I have a dropdown with an ajax option. When I select on of the rows, it give me back an option wich lead me to check/uncheck and enable/disable a checkbox. I can’t do the last part i.e update the checkbox in the ‘success’ function. My ajax return me the good result I can work on but i can’t go further…

can someone help me ?

My code :

<div class="row">

<?php echo $form->labelEx($model,'lesson_id'); ?>

<?php echo $form->dropDownList($model,'lesson_id', CHtml::listData($data, 'id', 'name'),

	array('ajax' => array(





                'success'=>'function(isPrivate) {


				$("#Enchainement_private").checked = true; // doesn't work

			} else {

				$("#Enchainement_private").checked = false;




		)); ?>

		<?php echo $form->error($model,'lesson_id'); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'private'); ?>				

		<?php echo $form->checkBox($model,'private'); ?>

		<?php echo $form->error($model,'private'); ?>		


Thanks in advance

[s]You need to call it as follows:


checked() is a function, not an attribute.

If isPrivate is boolean, you could simplify your code to:


If it’s not boolean, you could use:

$("#Enchainement_private").checked(isPrivate ? true : false);

That looks cleaner to me than the if / else structure for such a simple assignment.[/s]

Edit: All wrong. I’ve added the correct answer below.

Thanks for your answer but it doesn’t work.

Maybe it’s the selector (but when I write the result of the select in console.log, I obtain the checkbox …)

And do you know how to disable it too ?

Sorry, that’s me being idiotic and not checking properly.

If you’re using jQuery 1.6+, you can use this syntax:

$("#Enchainement_private").prop("checked", true);

You can use the same simplification as I suggested before.

In earlier versions you’ll need:

if (isPrivate)

    $("#Enchainement_private").attr("checked", "checked");



I’ll just edit my other post to remove the misinformation.

Yeah it works ! thanks a lot

and for the records I added

$("#Enchainement_private").prop("disabled", isPrivate);

to trigger enable/disable