I have testing and searching for my case, but still not work. Any help it so appreciated.
I have three select option that implemented php like this :
<div class="control-group" id="merkPrinter">
<label class="control-label" for="selectError">Merk Printer :</label>
<div class="controls">
<select id="selectError" data-rel="chosen">
<select id="selectError" class="chzn-done" data-rel="chosen" style="display: none;">
<option value="BRO">BROTHER</option>
<option value="EDM">EPSON DOT MATRIK</option>
<option value="EPD">EPSON DESKJET</option>
<option value="HPD">HP DESKJET</option>
<option value="HPL">HP LASERJET</option>
<option value="HPO">HP OFFICEJET</option>
<option value="KM">KOINICA MINOLTA</option>
<option value="PNS">PANASONIC</option>
</select>
</div>
</div>
<div class="control-group" id="tipePrinter">
<label class="control-label">Tipe Printer :</label>
<div class="controls">
<select id="selectPrinter">
</select>
</div>
</div>
<div class="control-group" id="tipeToner">
<label class="control-label">Tipe Toner :</label>
<div class="controls">
<select id="selectToner" disabled="disabled">
</select>
</div>
To passing data from my database, I am using ajax jquery like this :
$(document).ready(function($) {
$('#tipePrinter').hide();
$('#tipeToner').hide();
$("#merkPrinter").change(function() {
var id = $('#selectError option:selected').val(); // return value
if (id == "HPL") {
$.ajax({
url: '<?php echo base_url() . 'control_printer/getTypePrinter/' ?>',
type: 'POST',
data: {id: id
},
dataType: 'json',
success: function(obj) {
$('#tipePrinter').show();
$.each(obj, function(i, val) {
var content1 = "<option value=" + val.type + ">" + val.type + "</option>";
var content2 = "<option value=" + val.toner + ">" + val.toner + "</option>";
//List all of printer
$("#selectPrinter").append(content1);
//Dummy,
$("#selectToner").append(content2);
$('#tipeToner').show();
});
}
});
}
;
});
});
from this ajax, I got JSON like this :
[
{
"id_printer": "HPL",
"type": "3030, 1020, 3055",
"toner": "12A"
},
{
"id_printer": "HPL",
"type": "1200",
"toner": "15A"
},
{
"id_printer": "HPL",
"type": "P1106",
"toner": "35A"
},
{
"id_printer": "HPL",
"type": "PIXMAX",
"toner": "328"
},
{
"id_printer": "HPL",
"type": "1160, 1320",
"toner": "49A"
},
{
"id_printer": "HPL",
"type": "2015D",
"toner": "53A"
},
{
"id_printer": "HPL",
"type": "P1102, PRO1102W",
"toner": "CE285A"
}
]
Let say, the user choose HP Laserjet, the second select option would be showing type of printer e.g : "P1102, PRO1102W". In third select option just viewing toner based second select option that is "CE285A" . And so on, so on.
P.S : third select option is disabled
Thanks