Disable/enable Some Input Fields In Form Dinamically

Hello everybody,

Here is my will, in my form, I have many fields which depends on others, and I would like to be able to disabled or enabled these fields depending on what the user chose on the related fields.

Example : I have a dropdownlist field with 2 choices possible "PC" or "MAC". If the user chooses "PC" so the field Operating system stays enabled and the user can write anything he wants. If the user chooses "MAC" the field Operating system becomes disabled and the users cannot write in it anymore.

I guess I have to use javascript to reach that, but I don’t really know how to do it and maybe yii integrates already some functions or widgets to do it.


I am not sure if yii has something of that sort, but its very straight forward create something similar here is one i hacked it in 5 minutes

<!-- form  -->

<form action="" method="post">

	<select name="os" id="selec-os">

		<option value="pc">PC</option>

		<option value="mac">MAC</option>


	<input type="text" name="os" id="os-field" />

	<input name="submit" type="submit" value="Submit" />


<!-- javascript  -->

<?php Yii::app()->clientScript->registerCoreScript("jquery"); ?>

<script type="text/javascript">

$(document).ready(function() {


		if($(this).val() === "mac") {

			$("#os-field").attr("disabled", "disabled");

		} else {






Thanks alirz, I try it =D