$(function () {

	$("#asset_type").change(function(){
		$.ajax({
 	   		type: "POST",
 	   		data:{id:$(this).val(), type:''},
	    	url: "/assets-filter/listHardware",
 	   		success: function(data) {
 	   			$('#make_and_model').empty();
 	    		// $.each(data,function (key,value) {
 	    		// 	$('#make_and_model').append($('<option>', {
          		// 	  value: value.id,
          		// 	  text:  value.hardware  //value.manufacturer.name+" - "+value.name
       			// 	 })).trigger('chosen:updated');
 	    		// })

				 $.each(data, function(key, value) {
					// Create a text node to ensure the content is treated as plain text
					var textNode = document.createTextNode(value.hardware);

					// Create the option element using plain JavaScript
					var option = document.createElement('option');
					option.value = value.id;
					option.appendChild(textNode);

					// Append the option element to the select element
					document.getElementById('make_and_model').appendChild(option);
				});

        	}
 	 	});
	});

	$("#make_and_model").change(function(){
		$.ajax({
 	   		type: "POST",
 	   		data:{id:$(this).val(), type:''},
	    	url: "/assets-filter/listtechnics",
 	   		success: function(data) {
 	   			$('#technical_spec').empty();

 	    		// $.each(data,function (key,value) {
 	    		// 	$('#technical_spec').append($('<option>', {
          		// 	  value: value.id,
          		// 	  text:  value.details  //value.manufacturer.name+" - "+value.name
       			// 	 })).trigger('chosen:updated');
 	    		// })

				$.each(data, function(key, value) {
					// Create a text node to ensure the content is treated as plain text
					var textNode = document.createTextNode(value.details);

					// Create the option element using plain JavaScript
					var option = document.createElement('option');
					option.value = value.id;
					option.appendChild(textNode);

					// Append the option element to the select element
					document.getElementById('technical_spec').appendChild(option);
				});

        	}
 	 	});
	});

})