1
I have a code that I need to take the value selected by the user and my code always takes the last select code.
<?php
$tipo_info = 0;
echo "<fieldset>Selecione, qual o tipo da informação que deseja cadastrar.<br />";
$query = $con->query("SELECT * FROM pv_tipo_info_questionario");
echo "<select>";
echo "<option></option>";
while($reg = $query->fetch_array()) {
echo "<option name='ativo' value='".$reg["cod_tipo_info"]."'>".$reg["tipo_info_questionario"]."</option>";
$tipo_info = $reg["cod_tipo_info"];
}
echo "</select>";
echo "<br /><br />";
switch ($tipo_info){
case 1:
echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
break;
case 2:
echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
break;
case 3:
echo "<button type=\"button\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
break;
case 4:
echo "<button type=\"submit\" disabled=\"true\" class=\"avancar btn btn-primary pull-right\">Avancar</button>";
break;
}
?>
I don’t understand, @abfurlan. Your code is almost the same as mine, except for the name in select. I made this change to keep the pattern and it hasn’t changed anything. The big problem is:
'$tipo_info = $reg["cod_tipo_info"];
' If you are going to do the table test or the Chinese test, it will go through while and will include one, two, three and get the result 4. Maybe I have to create an array list. Someone can help me?!?– fabricio_wm
@fabricio_wm, then your problem is another and not picking the selected value in
select
, it is not very clear the problem, perhaps it would be interesting to edit the question and try to be more specific– abfurlan
@fabricio_wm If I understand, you want it to be released to submit the form only if the user selects the option with select value 4, that’s it?
– abfurlan
Yes. Pq the other buttons are type="button", that is, they do nothing. Only option 4 that will give an Submit pq the type="Submit".
– fabricio_wm
I created a form with PK in the head of the form and this way, the system administrator will be able to insert questions in the amount she wants and will select for question 1 the answer can be of type select, Yes or no (radio button) or a note. Got it?
– fabricio_wm
Look at this: <br/> I don’t want to end the existing programming here. http://jsfiddle.net/U7Vvb/4/ But I did get another way. http://jsfiddle.net/dieegov/kN84b/2/
– fabricio_wm
@fabricio_wm, yes I would suggest to do as javascript, more I advise you to treat the value of the post in php.
– abfurlan