Cakephp获取元素值的js助手


cakephp get element value js helper

我是CakePHP的初学者,尝试搜索这个问题,但没有任何黄金。我有一个选择按钮,当用户选择一个选项时,我必须触发一个事件,并将选择的值传递给控制器的动作。代码如下:


<?php
//I only need a select button why to bother of creating form
echo $this->Form->input('district',array('label'=>'labelhere','id'=>'idhere'));
//script handler for select option
$this->Js->get('#idhere');
$this->Js->event(
        'change',
        $this->Js->request(
            array('action' => 'listing',<the selected value of #idhere here>),
            array('async' => true,
                'method'=>'POST',
                'update' => '#HFNames')
        )
    );
?>
<div id="HFNames">
Div to include ajax returns.
</div>

准确地说,什么是CakePHP等价于Jquery的$('selector').value();

下面是生成的Html代码:
<html>
<div class="input select"><label for="idhere">labelhere</label><select  name="data[district]" id="idhere">
<option value="01">Bhojpur</option>
<option value="02">Dhankuta</option>
<option value="03">Ilam</option>
<option value="04">Jhapa</option>
<option value="05">Khotang</option>
<option value="06">Morang</option>
<option value="07">Okhaldhunga</option>
<option value="08">Panchthar</option>
<option value="09">Sankhuwasabha</option>
<option value="10">Saptari</option>
<option value="11">Siraha</option>
</select></div>
</html>

try this

<?php
//I only need a select button why to bother of creating form
echo $this->Form->input('district',array('label'=>'labelhere','id'=>'idhere'));
//script handler for select option
$this->Js->get('#idhere');
$this->Js->event(
        'change',
        $this->Js->request(
            array('action' => 'listing'),
            array('async' => true,
                'method'=>'POST',
                'update' => '#HFNames',
                'data'   => '$("selector").value()')
        )
    );
?>
<div id="HFNames">
Div to include ajax returns.
</div>

抽出时间阅读这篇文章:动态Web With Cake