Thursday, September 8, 2022

[FIXED] How to show day from input date in CodeIgniter

Issue

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


Solution

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);
}


Answered By - Alooishus
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

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