Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » event onchange 2 Dropdown

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

Page: 1
Go to End
Author Topic: 1229 Views
  • majo
    Avatar
    Community Member
    2 Posts

    event onchange 2 Dropdown Link to this post

    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.

    1229 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.