I have an HTML page where the user selects the information he needs and stores it in the database when he completes the operation. It's a small form in which virtually you only have check boxes in except a single text box. In one of the checkboxes (type problem), when the user clicks the "Machines" option, another select appears, in this case, the machine. And if the user chooses the "Other" option, then it will open the only text box on the page. Here's the code to follow.
HTML:
<select name="tipobroblema" id="tipoproblema">
<option value="">- Tipo Problema -</option>
<option value="maquina">Maquina</option>
<option value="vazamento">Banheiro</option>
<option value="arcondicionado">Ar Condicionado</option>
<option value="outro">Outro</option>
</select>
<div id="divOutro" style="display:none;"><input type="text" name="outro" /></div>
<select id="divMaquina" name="maquina" style="display:none;">
<option value="">- Maquinas -</option>
<option value="maquina1">Maquinas1</option>
<option value="maquina2">Maquinas2</option>
<option value="maquina3">Maquinas3</option>
<option value="maquina4">Maquinas4</option>
</select>
Script:
<script>
$('#tipoproblema').change(function(){
if(this.value == 'maquina') {
$('#divMaquina').css('display', '');
$('#divOutro').css('display', 'none');}
else if(this.value == 'outro') {
$('#divMaquina').css('display', 'none');
$('#divOutro').css('display', '');}
else {
$('#divMaquina').css('display', 'none');
$('#divOutro').css('display', 'none');}
});
</script>
When the user clicks "Generate" to write to the database, the data will go to a PHP page, thus using the POST to get the data that was informed by the user. Before adding the "Interactive" text box and checkbox (which appear depending on the option selected). I used only:
$problema = $_POST['tipoproblema'];
So, taking the value that the user selected and passing it to a variable.
As there was only one, there was no difficulty. It searched for the field name, in case "tipoproblema" would pick up the selected value and store it in the database. Now there are three possibilities. That is, as it was, it would continue to store the types of problems in the database (such as the value of "other" and "machines" instead of writing the selected machine or the text entered by the user). I do not understand much of PHP so far, I would greatly appreciate your collaboration.