So i'm trying to fill three select boxes at the same time, when page load. The data for boxes is from array's. So one box for $cpuArr, one box for $motherboardsArr and one box for $videocardArr.
PHP
$cpuArr = file_get_contents('data/cpu.json');
$motherboardsArr = file_get_contents('data/motherboard.json');
$videocardArr = file_get_contents('data/video-card.json');
if(isset($_POST['request']) == 1){
echo $cpuArr;// Sending response
}
jQuery
$(document).ready(function(){
//Ajax request
$.ajax({
url: 'logic.php',
type: 'post',
data: {request: 1},
dataType: 'json',
success: function fetchItems(response){
for( var i = 0; i< response.length; i++){
$('#cpu').append("<option value='"+response[i]['ID']+"'>"+response[i]['Name']+"</option>");
}
}
});
});
HTML
<select id='cpu'>
<option value="0">-Select CPU-</option>
</select>
<select id='motherboard'>
<option value="">-Select motherboard-</option>
</select>
<select id='video-card'>
<option value="">-Select Video Card-</option>
</select>
Its working only for one, i dont know how to make it with three boxes, without repating the code.I will be grateful if anyone can help. :)