type radio with different names

Asked

Viewed 47 times

0

I wonder how I can do for when one radio is marked the other unchecks, but the two with different names.

<span style="text-shadow: 0 0 7px blue; color: white; font-size: 15px; font-family: 'Kanit', sans-serif;">USA</span>
<input type="radio" id="usa" name="usa" value="usa">
<span style="text-shadow: 0 0 7px blue; color: white; font-size: 15px; font-family: 'Kanit', sans-serif;">BRAZIL</span>
<input type="radio" id="brazil" name="brazil" value="brazil">

  • If they represent the same type of data and are mutually exclusive, then they should have the same name. To do otherwise will be gambiarra and will not be recommended.

1 answer

0

There is no way, you have to give the same name to each, the name is the category of the item and not the value, the value is what PHP will receive, type, you what changes is the value.

That is to say, name is category "Land" (Country, origin, etc.) And the value is the selection that the user makes user/client.

Example:

<form onchange="alert('Seu país é '+this.pais.value+'\r\nForma de pagamento: '+this.pagamento.value)">
<p>Seu país atual:</p>
  <input type="radio" name="pais" value="BRASIL" checked>Brasil<br>
  <input type="radio" name="pais" value="URUGUAI">Uruguai<br>
  <input type="radio" name="pais" value="E.U.A">Estados Unidos da América<br>
<!-- Forma de pagamento -->
<p>Escolha sua forma de pagamento:</p>
  <input type="radio" name="pagamento" value="CREDCARD" checked>Cartão de Crédito<br>
  <input type="radio" name="pagamento" value="CHEQUE">Cheque nominal<br>
  <input type="radio" name="pagamento" value="BOLETO">Boleto<br>
</form>

Used Chebox:

<form>
  <input type="checkbox" name="pais1" value="Brasil">Brasil<br>
  <input type="checkbox" name="pais2" value="EUA">Estados Unidos da América<br>
</form>

  • So please, rephrase your question, because that’s what I understood in the request, if you set one to unmask the other. Still I will edit the answer and you will understand that each radio NAME is for a choice, if you want to select more than one you will have to use CHECKBOX.

  • In fact I would like each radio to be a post, for example, if the person selects Brazil, the code makes all the request that is in if ($_POST['Brazil']).

  • I’m sorry, but there’s not much to it, since the right thing would be if ($_POST['pais'] === 'brazil'){//tu é BR muleke}

  • This way it worked, but there’s no way I can stop you from scoring both at the same time?

  • Did you see that I edited the answer? In the first example I explained that the use of name who does just what you asked now. Then you said you wanted to select both and now you’re back to asking me to stop you from selecting both... I would like you to reformulate the main question and if possible see the TOUR: https://answall.com/tour And read this: https://answall.com/help

Browser other questions tagged

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