Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

event onchange 2 Dropdown




Community Member, 2 Posts

5 August 2010 at 7:53am

Edited: 05/08/2010 8:14pm

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.

(function($) {
$("#MyForm_mujForm_ulice").change(function () {
$("#MyForm_mujForm_ulice option:selected").each(function () {
//Now what?

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){
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.