Skip to content
Advertisement

How to show day from input date in CodeIgniter

I want to show day into textbox based on my input date

here is my ajax to change the textbox :

$("#date").change(function(){
            
        $.ajax({
          url : "<?php echo base_url();?>daftar/get_day",
                method : "POST",
                data : {date: $("#date").val()},
                async : false,
               
                success: function(data){
                
                    $("#day").val(day);
                
                }
                
            });
            
        
            
        });

this is my controller :

function get_day()
    {
        $date=$this->input->post('date');
        
        $this->load-model('daftarmodel');
        $day = $this->daftarmodel->geDay($date);
        
        echo $day;
      
    }

this is my model :

function getDay($date){
        
        $timestamp = strtotime($date);

        $day = date('D', $timestamp);
        var_dump($day);
        
        return $day;
        
        
    }

is there anything wrong with my code which not showing the day

Advertisement

Answer

Not sure if this is the part of your problem, but looks like you may be using the wrong variable in your ajax success.

success: function(data){
   $("#day").val(day);
} 

you could try replacing “day” with the “data” variable that is in your: “success: function(data)”

success: function(data){
   $("#day").val(data);
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement