Welcome Guest, Not a member yet? Register   Sign In
added new form_input() via ajax but set_value doesn't print anything on submit
#1

[eluser]Unknown[/eluser]
i have a form that use dropdown button when changing it add more form element (form_input) via ajax but when i submit it, it seems new form element was not sent to controller. not sure if this bug or there is other way to do this.
thanks before
#2

[eluser]CroNiX[/eluser]
Not sure how it would be a bug since CI doesn't do anything ajax-related. You have to custom code that.

You should show your view code with the form as well as your javascript where you are injecting a form element as well as your ajax call. Very hard to tell what you're doing with no code.
#3

[eluser]Unknown[/eluser]
view, i deleted most thing because of character limitation Sad
Code:
<td width="414">
                <table border="1">
                &lt;?php // Change the css classes to suit your needs    
            
                $attributes = array('class' => '', 'id' => '');
                echo form_open('c_input', $attributes); ?&gt;
                <tr>
                        <td><label for="jenis_perawatan">Jenis Perawatan <span class="required">*</span></label>
                        &lt;?php echo form_error('jenis_perawatan'); ?&gt;</td>
                        
                        <td>&lt;?php // Change the values in this array to populate your dropdown as required ?&gt;
                        &lt;?php $options = array(
                                                                  ''  => 'Please Select',
                                                                  'rawat_inap'    => 'Rawat Inap',
                                                                  'rawat_jalan'    => 'Rawat Jalan'
                                                                ); ?&gt;
                
                        &lt;?php
      $js = 'id = "jenis_perawatan" onChange="showUser(this.value);"';
      echo form_dropdown('jenis_perawatan', $options, set_value('jenis_perawatan'), $js)
      ?&gt;
                        </td>
                </tr>      
                <tr>
                        <td><label for="bagian">Bagian <span class="required">*</span></label>
                        &lt;?php  echo form_error('bagian'); ?&gt;</td>
                        
                        <td>
      &lt;?php $options = array(
                                                                  ''  => 'Please Select'
                                                                );
                        //echo $tindakan_medis;
      if($bagian->num_rows() >0)
                        {
                              foreach($bagian->result() as $rows)
                              {
                                $options[$rows->nama_bagian] = $rows->nama_bagian;
                              }
                        }
                        ?&gt;
                        
                        &lt;?php echo form_dropdown('bagian', $options, set_value('bagian'))?&gt;
                        </td>
                </tr>  
</table>
            </td>
            <td width="400" >
                <table border="1" id="tabHitung" >
                
                </table>
    <br>
                <table border="1" id="tabQuery" >
                  
                </table>
            </td>

ajax
Code:
function showUser(str)
{
if (str=="")
{
  document.getElementById("tabHitung")[removed]="";
  return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
  xmlhttp.onreadystatechange=function()
{
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
   document.getElementById("tabHitung")[removed]=xmlhttp.responseText;
  }
}
//var domain = /:\/\/([^\/]+)/.exec([removed].href)[1];
xmlhttp.open("GET",[removed] + "/ajaxquery/" +str,true);
xmlhttp.send();
}

ajax call
Code:
function ajaxquery($datas)
{
  switch($datas)
  {
   case "rawat_inap" :
   echo "belom dibuat";
  
   break;
   case "rawat_jalan" :
    
    $data['queri_rawat'] = $this->m_edit->get_rawat('rawat_jalan');
    
    echo "<tr>";
     echo "<td colspan=\"2\">";
     echo "Jenis Tindakan";
     echo "</td>";
     echo "<td colspan=\"2\">";
     echo "<select id=\"jenis_tindakan\" >";
     echo "<option id=\"\">Please Select</option>";
     echo "<optgroup id=\"tindakan_medis\" label='Tindakan Penunjang'>";//lab radio fisio
      echo "<option id=\"tindakan_medis\">Fisioterapi</option>";//Operasi
      echo "<option id=\"tindakan_medis\">Laboratorium</option>";
      echo "<option id=\"tindakan_medis\">Radiologi</option>";
     echo "</optgroup>";
     echo "<optgroup id=\"tindakan_medis\" label='Tindakan Medis'>";
      echo "<option id=\"tindakan_medis\">ICU</option>";
      echo "<option id=\"tindakan_medis\">Operasi</option>";
      echo "<option id=\"tindakan_medis\">RPK</option>";
      echo "<option id=\"tindakan_medis\">RPK Anak</option>";
     echo "</optgroup>";
     echo "<option id=\"tindakan_medis\">Tindakan Ruangan</option>";
     echo "</select>";
     echo "</td>";
    echo "</tr>";
    
    echo "<tr>";
     echo "<td colspan=\"2\">";
      echo "Rumus Pembagian";
     echo "</td>";
    
     echo "<td>";
      echo "<select id='rumus_pembagian'>";
      $i=0;
       foreach($data['queri_rawat'] as $row):
        if($i<1):
         echo "<option value=\"\">Please Select</option>";
         $i++;
        endif;
        echo "<option value=" . $row['id'] . ">" . $row['jenis_tindakan'] . "</option>";
       endforeach;
      echo "</select>";
     echo "</td>";
    echo "</tr>";
    
    echo "<tr>";
     echo "<td colspan=\"2\">";
     echo "Nilai Tindakan";
     echo "</td>";
     echo "<td>";
     echo "&lt;input type=\"text\" id=\"nilai_tindakan\" name=\"nilai_tindakan\"&gt;";
     echo "</td>";
    echo "</tr>";
    
   break;
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB