Get selectbox value with JsHelper in CakePHP

I have a selection box and I want to use it for Ajax-update of other content on the page. So I linked the event handler using JsHelper (jQuery) as follows:

<?php echo $this->Form->select('car', $cars); $this->Js->get("#car"); $this->Js->event('change', $this->Js->request(array( 'controller' => 'cars', 'action' => 'view', ???, array('async' => true, 'update' => '#car-view', 'evalScripts' => true), true )); ?> 

But how can I get the value of the selection field to send as an argument to the car controller (in "???" in the code above)?

I could do everything in javascript, but is there any way to do this in the cake?

+4
source share
2 answers

Honestly, I struggled with this for a while. I could not find anything that worked, so I just switched to the direct javascript route.

+1
source

I think you are looking for this:

 $this->Js->get('#selectbboxid1')->event('change', $this->Js->request(array( 'action' => 'function'), array( /*'before' => 'showLoader();', 'success' => 'hideLoader();',*/ 'update' => '#selectboxid2', 'dataExpression'=>TRUE, 'method'=>'POST', 'async'=>TRUE, 'data' => $js->serializeForm(array('isForm' => TRUE, 'inline' => TRUE)) ))); 
+1
source

Source: https://habr.com/ru/post/1336972/


All Articles