Creating active form dropdown list using jquery

Hi guys i want to share something to you since it took me hours to figure this out and unable to google it.

if you can improve this please do tell me.

i have the scenario where i have a employee table and a company table where i can add many company and selecting from a dropdownlist insted of inputing a company for every employee. so which means i can add many dropdownlist that contains list of company.

hope this will help to someone.

<?php

$str=$form->dropdownList($model,“CompanyId”,CHtml::listData(Company::model()->findAll(),‘id’,‘name’));

?>

<script>

$(’#add_dropdownlist’).click(function(){

$(’.class_div’).append(’<?php echo $str = str_replace("\n", “”,$str); ?>’);

});

</script>