Display field sex select box with another value

Asked

Viewed 366 times

0

I’m trying to display the outcome of my sex field with another value. In the bank ta as F and M but in my edit I would like the result appears as male or female. I tried with if-else but I couldn’t. 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> 

1 answer

1


Tell you what... I don’t know if this is it but that’s what I understood, you want it to come selected the amount that’s in your bank... 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> 

nevertheless if-else only ternary, but works with anyone. = D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.