Need select box dropdown onchange event code

hi i m using cakphp 1.3 …i dont know to pass value from ajax to controller and dont know to get the value in controller from view via post or get method…so please help me with code including view and controller code… thank you in advance…!!

That’s a bit rude of you guys to say tbh…
sure, it doesn’t have to do directly with CakePHP, but at least help the guy out…

If you’re using jQuery, you can do something like:

$("#myDropdown").on('change',function(){
  // Do stuff here
});

Also, I’d recommend trying to upgrade to CakePHP 2.x or 3.x since 1.3 is no longer supported and thus, leaves you open to bugs in the framework, security flaws etc.

1 Like

thank you for your valueable response …i juz get the select box value in jquery …but dont know to pass the value from ajax to controller…

you should use a POST or GET (or w/e) for that eg:

var request = $.ajax({
  url: "mydomain.com/my/route",
  method: "POST",
  data: { variablename : value },
  dataType: "json"
});

I can’t really help you out with the specifics as it wouldn’t really have to do much with CakePHP itself…

Something like this

$.ajax({
            type: "GET",
            url: "/xxx/yyy",
            data: {
                data: $('#object').val(),
            },
            success: function(result) {
            },
            error: function(result) {
            }
        });

Though you probably want it to be a POST instead of a GET

sure i will upgrade soon sir …thank you for the response…This project completed before 10 years sir…lot of users suggestion some changes doing now sir so only doing some work…anyways thank you for the valueable response…

thank you to the greatest response sir…i was tried these steps already sir in google sir …but i cant get the dropdown onchange value from view to controller sir… this is the main issue for me sir …so i need controller code sir…

The controller code shouldn’t really matter to much for what you want.

I have not tested this code, but it should be pretty much straight forward like this if you know the basics of Javascript.

$("#myDropdown").on("change",function(){
  $.ajax({
    type: "POST",
    url: "/xxx/yyy",
    data: {
      data: this.value, // should be the value of the selected dropdown item
    },
    success: function(result) {
    },
    error: function(result) {
    }
  });
});