title: CodeIgniter Update database using ajax button
body: <p>I'm trying to update my data using an update button.</p>
  
  <p>What I want to do is: </p>
  
  <blockquote>
    <p>When I click my data it turns into an input field where I can modify
    the data and then when I click the update button the data should be
    updated.</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/lORuB.jpg" alt="enter image description here"></p>
  
  <blockquote>
    <p>I have the <code>update button</code> (the yellow button in picture) ready and the <code>data input field</code> is also ready
    where I used <code>jQuery</code> found on net.</p>
  </blockquote>
  
  <p>I don't know much about Ajax and jQuery. Database field names I want to update are <code>tname</code> and <code>time</code> </p>
  
  <p>I need <code>Update Method</code> in <code>Controller</code>, <code>Update Method</code> in <code>Model</code> and <code>Codes</code> in <code>View</code> </p>
  
  <p>Onclick turns into Input field codes:</p>
  
  <pre><code>&lt;script&gt;
   var switchToInput = function () {
                       var $input = $("&lt;input&gt;", {
                       val: $(this).text(),
                       type: "text"
                   });
  
              $input.addClass("loadNum");
              $(this).replaceWith($input);
              $input.on("blur", switchToSpan);
              $input.select();
        };
  
      var switchToSpan = function () {
                         var $span = $("&lt;span&gt;", {
                         text: $(this).val()
                         });
  
              $span.addClass("loadNum");
              $(this).replaceWith($span);
              $span.on("click", switchToInput);
      }
        $(".loadNum").on("click", switchToInput);
  &lt;/script&gt;
  </code></pre>