0
I intend to make the field "Idsiliamb" mandatory, only when the radio button "Company" is selected, if the field "Private" is selected nothing will happen.
At the moment when I select the radio button "Company" the text field "Idsiliamb" is scintillating, but it does not display the error message and allows me to insert even when empty.
<form class="form-horizontal"  method="POST" action="index.php?cmd=addter2" > 
   <div class="form-group">
    <label class="control-label col-sm-4" for="Idsiliamb"> Idsiliamb </label>
    <div class="col-sm-6"> 
      <input type="text" class="form-control" id="Idsiliamb" placeholder="Digite o Idsiliamb" name="Idsiliamb" onclick="document.getElementById('Empresa').checked=true">
    </div>
  </div>
   <div class="form-group">
    <label class="control-label col-sm-4" for="Tipo"> Tipo  </label>
    <div class="form-group">
    <input type="radio" name="Tipo" id='radio_r' value="Empresa" onclick="document.getElementById('Idsiliamb').focus()" required>Empresa
    <input type="radio" name="Tipo" id='radio_p' value="Particular" >Particular
    </div>
  </div>
  <br>
  <div class="form-group"> 
    <div class="col-sm-offset-4 col-sm-6">
      <button type="submit" class="btn btn-default">Adicionar Terceiros </button>
    </div>
  </div>
</form>
<script>
	$('input[name="Tipo"]').change(function () {
		if($("#Empresa").is(':checked')) {
			$('#Idsiliamb').attr('required', true);
		} else {
			$('#Idsiliamb').removeAttr('required');
		}
	});
</script>  <style>
#Idsiliamb[required] {
    background: #FFAAAA;
}
</style>
I’ve noticed where I went wrong and I’ve been corrected, thank you anyway !
– Someone