0

I am beginner to CakePHP and tried searching this question but no any gold. I have a select button and when user select an option I have to fire a event and pass the selected value to the controller's action. The code goes below:


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

Precisely, What is the CakePHP equivalent for Jquery's $('selector').value();

Here is the Html code generated:

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

2
  • Give the html source of the input. Commented Apr 2, 2013 at 5:23
  • 1
    which html is generated by echo $this->Form->input('district',array('label'=>'labelhere','id'=>'idhere')); Commented Apr 2, 2013 at 5:26

1 Answer 1

2

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>

make time to read this post: Dynamic Web With Cake

Sign up to request clarification or add additional context in comments.

1 Comment

var_dump($this->request->data) in your function listing to see how data came.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.