added new form_input() via ajax but set_value doesn't print anything on submit - El Forum - 09-05-2012
[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
added new form_input() via ajax but set_value doesn't print anything on submit - El Forum - 09-05-2012
[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.
added new form_input() via ajax but set_value doesn't print anything on submit - El Forum - 09-05-2012
[eluser]Unknown[/eluser]
view, i deleted most thing because of character limitation
Code: <td width="414">
<table border="1">
<?php // Change the css classes to suit your needs
$attributes = array('class' => '', 'id' => '');
echo form_open('c_input', $attributes); ?>
<tr>
<td><label for="jenis_perawatan">Jenis Perawatan <span class="required">*</span></label>
<?php echo form_error('jenis_perawatan'); ?></td>
<td><?php // Change the values in this array to populate your dropdown as required ?>
<?php $options = array(
'' => 'Please Select',
'rawat_inap' => 'Rawat Inap',
'rawat_jalan' => 'Rawat Jalan'
); ?>
<?php
$js = 'id = "jenis_perawatan" onChange="showUser(this.value);"';
echo form_dropdown('jenis_perawatan', $options, set_value('jenis_perawatan'), $js)
?>
</td>
</tr>
<tr>
<td><label for="bagian">Bagian <span class="required">*</span></label>
<?php echo form_error('bagian'); ?></td>
<td>
<?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;
}
}
?>
<?php echo form_dropdown('bagian', $options, set_value('bagian'))?>
</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 "<input type=\"text\" id=\"nilai_tindakan\" name=\"nilai_tindakan\">";
echo "</td>";
echo "</tr>";
break;
}
}
|