PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to change cakephp default value in select List?

 April 22, 2022     cakephp, cakephp-2.3     No comments   

Issue

I need to change cakephp default value from select box.Here in controller I have coded

$madDivisions = $this->MadStore->MadDivisions->find('list');

In view

<?php
      echo $this->Form->input('mad_divisions_id',array( 'label' => false, 'class'=>'form-control','id'=>'select' ));
?>

After add jquery val() method

<script>
    $('#select').change(function(){
        var a=$('#select').val();
        alert(a);
    })
</script>

It showing me 1,2......

But I want to change this default value and want to replace divisions name as a value.Like as

<option value="London">London</option>
<option value="Dhaka">Dhaka</option>

Solution

Try this for find method with list

    $madDivisions = $this->MadStore->MadDivisions->find(    'list', 
                                                            array(
                                                                    'fields' => array(
                                                                                    'city_name', 
                                                                                    'city_name'
                                                                                )
                                                            )
                                                        );

city_name is the column name from database table which contains values for London, Dhaka.



Answered By - Pankaj Badukale
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing