Can anybody point me to some source of examples How to use javascript in Yii?
e.g.
I have form with radiocheck where one can check male or female. After that there is activeDropDownList where you can choose size of a shoes. If you are man -> male size, if women -> female size.
Can you show me how can I change data (listData()) in activeDropDownList using pure javascript? I found some example but always with ajax and some controller/action , so not directly on the page.
Is it any evidence to do this way than on the page? Is this pattern (ajax->controller on the server -> page) better than js on page? I understand that this is much more conform MVC , personlly dont like js so Iam happy with your recommendation. But I want code according "the best practises"…
I rebuild my old pages about obesity. I got personal height and weight in the form. If BMI (body mass index = weight/height^2) is < 25 then user is able to choose from dropDownList different scenarios “how to lose weight”. So I have data for a dropDownList in advance and I use javacsript only for choosing correct offer in a dropDownList. And I want to rewrite using Yii. That’s all
I found some example where there are direct use of javascript:
CHtml::link(,array(‘onclick’=>‘return someFunction()’) or CHtml:clientChange() but I coudn’t find right way (usage of clientChange() I totally missed ).
Sure ajax is way how to do that but I think maybe to robust for such simple example.
I thing you will use plain javascript, the only need is to know the id of the elements of the page (I suppose of the form) and with CHtml (there is a htmloptions as I know array(‘onchange’=>‘myfunction’) I thing you can set them by yourself.
<?php
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>'dynamiccities', //url to call
//'update'=>'#city_id', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
'success'=>'js: function(msg) { alert(msg); }'
)));
echo "<br>";
//empty since it will be filled by the other dropdown
echo CHtml::dropDownList('city_id','', array());
?>
When I change dropDownList (country_id) page generates ajax request (see. if(Yii::app()->request->isAjaxRequest) but I can’t get any data from $_POST. Where do I mistake?