Monday, September 16, 2013

Display dynamic checkbox in cakephp using Jquery

Hi All,


   I want to display "checkbox"  dynamically after the  value is being entered in input box .
  So far i have done analysis and couldn't display the correct values in checkbox .

  Here what i did:
  
#sw is id for input text box.

#releaseValue : where checkbox needs to be created dynamically

 js file:

    $('#sw').focusout(function(){
            var parent=$('#releaseValue');
                if($(this).val())
                {
                    $.get(url,function(data){
                            for(key in data)
                        {
                            var div = $('<div/>').attr({'class':'ui-dform-div field checkbox cf','id':'del'});
                            var input = $('<input/>').attr({'type':'checkbox', 'name':name, 'class':'ui-dform-checkbox', 'value':data[key]});
                            var label = $('<label/>').attr('class', 'ui-dform-label').text(data[key]);
                            parent.append(div.append(input).append(label));
                        }
                        });
                       
                }


URL: controller/method.json?field=$(this).val()


Controller.php

public function method()
    {
   
        $values = array();
        $field = @$this->request->query['field'];
            $inputValue = @$this->request->query['term'];
            $query=array('key'=> $inputValue);
            $field=array('value');
            $v=$this->model->find('all',array('fields'=>$field,'conditions'=>$query));
            
            $this->set('values', $v[0]['model']['value']);
        $this->set('_serialize', 'values');
   
    }


The above code i have tried but the problem is " method in controller couldnot be found " error i'm getting when try to exceute code and this url is passed through routes.php ,where default configuration for routing is being called .

can anyone please help where the problem lies .



--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: