1
I have a select with five option. I want it to check the link the user is and as this link, it selects an option.
My HTML:
<select name="segmento" id="segmento" class="basic">
<option value="">Segmento</option>
<option value="Teste Engenharia">Teste Engenharia</option>
<option value="Teste Hospitalar">Teste Hospitalar</option>
<option value="Teste Iluminação">Teste Iluminação</option>
<option value="Teste Elevadores">Teste Elevadores</option>
</select>
I’m trying to do via PHP with preg_match, but my knowledge is limited, so I’m probably doing something wrong.
What I’m trying to do:
<option
<?php
if (preg_match( '/segmentos\/teste-hospitalar/',$database->parametros['menuRoteador']))
echo 'value="teste Hospitalar" Teste Hospitalar';
elseif (preg_match('/segmentos\/neomot-elevadores/',$database->parametros['menuRoteador']))
echo 'value="Teste Elevadores" Teste Elevadores';
elseif (preg_match('/segmentos\/neomot-engenharia/',$database->parametros['menuRoteador']))
echo 'value="Teste Engenharia" Teste Engenharia';
?>
>
</option>
He should be occupied with the value of <option value="">Segmento</option>, but this is not happening.
But the
optionis closed at the end of PHP– Felipe Viero Goulart
@Felipestoker Yes, you’re closing the
option, but is forgetting to close the tag of beginning ofoption. See how it’s getting<option value="teste Hospitalar" teste Hospitalar></option>. To the browser theoptionhas 3 attributes:value,testeandHospitalar.– Oeslei
Ahh understood. You’re right. The problem is that in select it was like this
Teste Elevadores>, was left a>afterward.– Felipe Viero Goulart
@Felipestoker There’s one left
>after and missed one before =)– Oeslei
actually I had already made the modification you spoke about, look here as it is http://jsfiddle.net/o3y7yj3t/
– Felipe Viero Goulart
worked :D just found it strange that the closing of the
optionis green http://prntscr.com/61cinw– Felipe Viero Goulart
Change your logic, remove all php code from within the option and assign the value to a variable, then select vc puts this variable in the value and display text. Will make the code more readable.
– Luis Henrique
@Felipestoker It will get weird even in your IDE because it won’t be able to identify the closing of the option start tag. I added an alternative to the answer so that your IDE correctly identifies the code and makes it easier to interpret it.
– Oeslei
Perfect, I understand your explanation! :)
– Felipe Viero Goulart