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

Thursday, September 8, 2022

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

 September 08, 2022     ajax, codeigniter, html, javascript, php     No comments   

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)
  • 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