Zend_form_element_select onchange in zend framework

I have a form called createDevice.php as:

class Admin_Form_CreateDevice extends Zend_Form { public function init() { $this->setName('Create Device Access'); $sort=new Zend_Form_Element_Select('employee_name'); $sort->setLabel('Employee Name:'); $this->addElements(array($sort)); /* Form Elements & Other Definitions Here ... */ } } 

Now in a controller action called viewDeviceAction (), I called this form the following:

 public function viewDeviceAction() { echo 'viewDevice: '; $form_device=new Admin_Form_CreateDevice(); $form_device->setMethod('post'); $form_device->employee_name->addMultiOptions($aMembers);//here $aMembers is an array. $this->view->form=$form_device; } 

Now I want the following situation: If you select any value above the drop-down menu, you should call the javascript function (which is located in viewDevice.phtml). Generally html as:

 <select id="EmployeeId" onchange="loadDeviceId();"> 

So, I just want how to implement the onchange event in the select element in zend framework

+4
source share
2 answers

This can be added on the server side. When creating your item, add the details for the onchange event, as shown below.

 $sort=new Zend_Form_Element_Select('employee_name',array('onchange' => 'loadDeviceId();')); 

Now in your HTML output you will see "onchange = 'loadDeviceId();'" attached to your select element.

Mark my answer in another question .

+3
source

Since you want to implement an event handler for the onChange event, you will need to do this in javascript. There is no native way to implement it in PHP or the Zend Framework, as far as I know.

Using jQuery, you can do something like this:

 $('#employee_name').change(function() { //call your javascript function here }); 

You can even immediately call your function as follows:

 $('#employee_name').change(yourFunctionName); 

Hope this helps.

0
source

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


All Articles