Hello, I need to understand how to work with events in SilverStripe. Example:
For simplicity, I have 2 dropdown A and B. The need to respond to the OnChange And so I choose and obtain the data in b. Using jQuery I can catch OnChange event see code.
<script>
(function($) {
$(document).ready(function(){
$("#MyForm_mujForm_ulice").change(function () {
$("#MyForm_mujForm_ulice option:selected").each(function () {
alert($(this).text());
//Now what?
});
});
})
;
})
(jQuery);
</script>
Now I do not know how to call a function, who have in my control.
function onchange($request) {
$pol = array(1=>1,2=>2);
FormResponse::update_dom_id('MyForm_test', 'test');
FormResponse::status_message('Done', 'good');
return FormResponse::respond();
}
I modified the controller:
public function index(){
if(Director::is_ajax() == false){
return array();
}
$data = array( 'Test' => 'value');
return json_encode($data);
}
Ajax calls a function:
$("#lab").load('My_Controller', function(vystup){
$("#MyForm_mujForm_test").val(vystup.test);
alert("echo: " + vystup.test);
});
Unfortunately I can not get the value of the test. pops up in my error alert:
echo: undefined
A solution is parsed!!!!!!!
var obj = jQuery.parseJSON(vystup);
P.S. Sorry for my English.