CodeIgniter Forums
I can't get the value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: I can't get the value (/showthread.php?tid=777)



I can't get the value - bobykurniawan - 01-15-2015

Good day sir, i've a question about get the value. First please kindly check my view

Code:
    <script type="text/javascript">
     function shipper(){
       var shippername  = $("#shippername").val();
          if(shippername.length > 2){
                     $.post("<?=base_url(); ?>home/cekada/shipper", {
                         shippername: $('#shippername').val(),
                         },
      function(response){
                   setTimeout("finishAjax('Info', '"+escape(response)+"')", 450);
                     });
                   }else{
                        $('#Info').fadeOut(10);
                      }
              }
   function finishAjax(id, response){
     $('#'+id).html(unescape(response));
     $('#'+id).fadeIn(100);
   }
   </script>
<div class="col-sm-1 col-md-6">
       <div class="panel panel-default">
                       <div class="panel-heading">
                               <h3 class="panel-title">Data Shipper</h3>
                       </div>
                        <div class="panel-body">
                           <div class="form-group">
 <form role="form" method="post" action = "<?=base_url();?>home/siprocess">
                             <label> Name : </label>
                           <input type='text' onkeyup="shipper()" name='shippername' id='shippername' class="autocomplete form-control" />
                        </div>
                                   <span id='Info'>                              
                                   </span>  
                        </div>

       </div>
 </div>



Then here is my controller 


Code:
$shippername = strtolower($this->input->post('shippername'));
   $sql = "SELECT * FROM shipper where shippersname = '$shippername'";
   $hasil = $this->shippermodel->cariquery($sql);
   foreach($hasil as $result)
   {
       $address = $result->address;
       $phone = $result->phone;
       $fax = $result->fax;
   }
       if($hasil != NULL)
       {
           echo "
                   <div class='form-group'>
                      <label> Address : </label>
                       <textarea name='shipperaddress' class='form-control'>$address</textarea>    
                    </div>
                     <div class='form-group'>
                       <label> Phone Number : </label>
                       <input type='text' name='shipperphone' value='$phone' class='form-control'>
                     </div>
                     <div class='form-group'>
                       <label> Fax : </label>
                       <input type='text' name='shipperfax' value='$fax' class='form-control'>
                    </div>
              ";
       }

explanation.

I input the shippername field from the form then it'll show up the field fill up by the other data from database. But when i try to 


PHP Code:
$shippername $this->input->post('shippername');
        
$shipperphone $this->input->post('shipperphone');
        
$shipperfax $this->input->post('shipperfax');
        echo 
$shippername; echo $shipperphone; echo $shipperfax

only shippername have value.


Sorry for bad english


RE: I can't get the value - mwhitney - 01-16-2015

Your main problem is here:
PHP Code:
<div class="panel-body">
    <
div class="form-group">
        <
form role="form" method="post" action "<?=base_url();?>home/siprocess">
            <
labelName : </label>
            <
input type='text' onkeyup="shipper()" name='shippername' id='shippername' class="autocomplete form-control" />
    </
div>
    <
span id='Info'>
    </
span>
</
div

Even though it doesn't look like it, because you don't close your form tag anywhere in the code you provided, #Info, where you appear to be placing the result of your AJAX call to the controller, is probably going to be outside of your form in most browsers. Since the form can't leave the enclosing div without creating invalid HTML, most browsers will insert a closing form tag before the closing div tag, which occurs before the #Info span opens. If you do close your form tag somewhere after the code you've included here, it's likely that the browser has still inserted the closing tag and is (mostly) ignoring the closing tag you provided in your view.

You should be able to confirm this by using the developer tools for your browser to inspect the rendered HTML. Sometimes "View Source" will also show you where the closing form tag has been inserted.


RE: I can't get the value - bobykurniawan - 01-18-2015

(01-16-2015, 12:17 PM)mwhitney Wrote: Your main problem is here:

PHP Code:
<div class="panel-body">
 
   <div class="form-group">
 
       <form role="form" method="post" action "<?=base_url();?>home/siprocess">
 
           <labelName : </label>
 
           <input type='text' onkeyup="shipper()" name='shippername' id='shippername' class="autocomplete form-control" />
 
   </div>
 
   <span id='Info'>
 
   </span>
</
div

Even though it doesn't look like it, because you don't close your form tag anywhere in the code you provided, #Info, where you appear to be placing the result of your AJAX call to the controller, is probably going to be outside of your form in most browsers. Since the form can't leave the enclosing div without creating invalid HTML, most browsers will insert a closing form tag before the closing div tag, which occurs before the #Info span opens. If you do close your form tag somewhere after the code you've included here, it's likely that the browser has still inserted the closing tag and is (mostly) ignoring the closing tag you provided in your view.

You should be able to confirm this by using the developer tools for your browser to inspect the rendered HTML. Sometimes "View Source" will also show you where the closing form tag has been inserted.

Man, thanks for remind me about the closing tag. It's working now