Display field sex select box with another value

0

I'm trying to display the result of my gender field with another value. In the bank it's like F and M but in my edit I'd like the result to appear as male or female. I tried if-else but could not. My div is this:

 <div class="form-group col-md-2">
      <label for="ds_sexo"> Sexo</label>
      <select class="form-control" name="ds_sexo"id="ds_sexo">
   <option value="<?=$cliente->ds_sexo?>"><?=$cliente->ds_sexo?>//aqui que eu gostaria que aparecer  masculino ou feminino dependendo do resultado </option>

    <option value="F">FEMININO</option>
    <option value="M">MASCULINO</option>

  </select>
</div> 
    
asked by anonymous 12.09.2017 / 05:29

1 answer

1

Do the following ... I do not know if this is it but this is what I understood, you want the selected value in your bank to be selected ... would look like this:

<div class="form-group col-md-2">
  <label for="ds_sexo"> Sexo</label>
  <select class="form-control" name="ds_sexo"id="ds_sexo">
    <option value="F"<?= $cliente->ds_sexo == 'F' ? ' selected' : ''?>>FEMININO</option>
    <option value="M"<?= $cliente->ds_sexo == 'M' ? ' selected' : ''?>>MASCULINO</option>
  </select>
</div> 

It does not stop being if-else only ternary, but works with anyone. = D

    
12.09.2017 / 05:46