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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

event onchange 2 Dropdown


Go to End


2141 Views

Avatar
majo

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.

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