i want to use multiple select2 onchange function in a dynamic way

I want to put select2 function in my code but don't know where to put that .select2() function
i have this .append($(<?php echo json_encode($property_address1); ?>)) my model `

   function property_address1()
   {
     $query = $this->db->query('SELECT host,price,city,property_thumbnail, apartments_type, contactnumber, contactperson,photographlinks,emailid, propertyaddress FROM tbl_contacts')->result();
     $output = '<select id="neww" class="property_add_ form-control">';


    foreach ($query as $row) 
    {
        //echo $row->location;
        $output .= "<option value='". $row->propertyaddress ."'";
        $output .= " data-propertyaddress='" . $row->propertyaddress ."'" ;
        $output .= " data-host_name='" . $row->host ."'" ;

        $output .= " data-apartments_type ='" . $row->apartments_type."'" ;

        $output .= " data-city ='" . $row->city."'" ;

        $output .= " data-property_thumbnail='" . $row->property_thumbnail."'" ;

        $output .= " data-price='" . $row->price."'" ;

        $output .= " data-contactperson='" . $row->contactperson ."'" ;
        // $output. = $row->pincode.", ".$row->city.", ".$row->location;
        $output .= " data-photographlinks='" . $row->photographlinks ."'" ;
        $output .= " data-emailid='" . $row->emailid ."'" ;
        $output .= " data-contactnumber='". $row->contactnumber . "'>" ;
        $output .=   $row->host . ' , '.$row->propertyaddress . ' ,'.$row->price. ' ,'.$row->apartments_type. ' , '. $row->contactperson . ' , ' . $row->contactnumber. "</option>";
    }
    $output .= '</select>';
    //var_dump($output);
    return $output;

    }`

my controller

  public function test($id = null)
    {
        $this->layout->set(
                array(
                    'property_address1' => $this->mdl_quotes->property_address1()
                     )
                 );
        $this->load->model('mdl_quotes');
        $this->layout->buffer('content', 'quotes/test'); 
        $this->layout->render();
    }

Dhaval Panchal check this updated screenshot

This is screenshot for better understanding.. please have a look Thanks

Answers:

Answer

Insert CSS & JS file in your page then after JS file insert this code in your page.

<script type="text/javascript">
    $(document).ready(function() {
        $('#neww').select2();
    });
</script>

To update options, see below code.

var option = new Option("text", "id");
$("#neww").append(option);
$("#neww").trigger("change");

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.