views:

180

answers:

1

I've done some jQuery functions in a CakePHP project but finally I decided to try the Ajax Helper . Unfortunately I don't get the idea of how to pass a parameter (form field value) to the AJAX function. I did the following:

$obtainProduct = $ajax->remoteFunction( 
        array( 
        'url' => array( 'controller' => 'products', 'action' => 'obtain', '{$OrderProductId->id}'),
        'update' => 'post' ) 
); 

...

echo $form->input('product_id', array('empty' => true, 'onchange' => "$obtainProduct"));

It calls the function but without retrieving the parameter I need.

I got the idea from the API link docs -api.cakephp.org/class/ajax-helper and I want to get the ID from select box, get it's value and do some lookup in the backend.

So how can I get the ('#OrderProductId option:selected').val or something like this with the helper?

A: 

in cake php you have to use observe field i am assuming you are trying to populate a select box results

create( 'Product' ); ?>
input( 'product_id', array( 'empty' => true,'options'=>$defaultoptions) ) ?> end('submit');?>

observeField( 'ProductProductid', array( 'url' => array( 'controller'=>'products','action' => 'obtain' ), 'update' => 'PostProductid', ) ); ?>

Thats the php code i assume you know how to write the method and view to get the select box result. if having problem let me know.

dip1232001