2013-04-02 25 views
0

我是CakePHP的初学者,并试图搜索这个问题,但没有任何黄金。 我有一个选择按钮,当用户选择一个选项时,我必须触发一个事件并将选定的值传递给控制器​​的操作。 代码低于:cakephp获取元素值js helper


<?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的$( '选择')值()。

这里是生成的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> 

+0

给输入的HTML源代码。 – 2013-04-02 05:23:11

+0

什么是html源码? –

+1

其中html是由'echo $ this-> Form-> input('district',array('label'=>'labelhere','id'=>'idhere'))生成的;' – 2013-04-02 05:26:47

回答

2

试试这个

<?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> 

腾出时间来阅读这篇文章:Dynamic Web With Cake

+0

如何接受该数据在控制器? –

+0

'函数列表'中的var_dump($ this-> request-> data)'来查看数据是如何出现的。 – 2013-04-02 06:14:27