I have the following select
where I select a type of wood and this has sub products of this, but sometimes the wood has no sub product so it hides the select of the byproduct. But when rescuing the data and sending it to the AJAX database sends me the sub product being that the select
is hidden
Is there any way to leave the value of this select byproduct null?
$("#clasificacion").change(function() {
var valor = $(this).val(); // Capturamos el valor del select
var texto = $(this).find('option:selected').text(); // Capturamos el texto del option seleccionado
switch (texto) {
case 'Madera1':
$("#divhidden").first().show("fast", function() {});
var newOptions = {
"Madera1.1": "Madera1.1",
"Madera1.2": "Madera1.2"
};
var $el = $('#subclasificacion');
$el.html(' ');
$.each(newOptions, function(key, value) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
break;
case 'Madera2':
$("#divhidden").hide(100);
break;
case 'Madera3':
$("#divhidden").first().show("fast", function() {});
var newOptions = {
"Madera3.1": "Madera3.1",
"Madera3.2": "Madera3.2"
};
var $el = $('#subclasificacion');
$el.html(' ');
$.each(newOptions, function(key, value) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
break;
}
});
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="col-sm-3">
<small>Clasificacion Producto</small>
<select class="form-group browser-default custom-select" id="clasificacion">
<option selected disabled>.::Clasificacion::.</option>
<option value="Madera1">Madera1</option>
<option value="Madera2">Madera2</option>
<option value="Madera3">Madera3</option>
</select>
</div>
<div class="col-sm-3" id="divhidden">
<label>Sub Clasificacion Producto</label>
<select class="form-group browser-default custom-select" id="subclasificacion">
<option value="Madera1.1">Madera1.1</option>
<option value="Madera1.1">Madera1.2</option>
</select>
</div>
I hope to have explained myself well. Greetings