I have the following three fields:
1st Field:
<input class="emailrequerido" name="emailrecomendado1_<?php echo $patrocinado->idpatroc; ?>" id="emailrecomendado1_<?php echo $patrocinado->idpatroc; ?>" placeholder="[email protected]" type="text" />
2nd Field:
<select name="contactos<?php echo $patrocinado->idpatroc; ?>[]" id="contactos<?php echo $patrocinado->idpatroc; ?>" multiple="3" style="width:49%" class="contactorequerido">
3rd Field:
<select name="grupos<?php echo $patrocinado->idpatroc; ?>[]" id="grupos<?php echo $patrocinado->idpatroc; ?>" multiple="3" style="width:49%" class="gruporequerido">
Submit Field:
<input id="enviarForm" type="submit" class="uk-button uk-float-right" value="<?php echo JText::_('COM_CSTUDOMUS_PATROCINADOR_SEND_RECOM');?>"/>
I need to have always one of the three fields with a value before your allowed to submit.
I have tried the following:
$("#enviarForm").click(function() {
if($(".emailrequerido").val() == false){
$('.contactorequerido').attr('required', true);
$('.gruporequerido').attr('required', true);
}else if($(".contactorequerido option:selected").val() == false){
$('.emailrequerido').attr('required',true);
$('.gruporequerido').attr('required',true);
}else if($(".gruporequerido option:selected").val() == false){
$('.emailrequerido').attr('required',true);
$('.contactorequerido').attr('required',true);
}
if($(".emailrequerido").val() == true){
$('.contactorequerido').removeAttr('required');
$('.gruporequerido').removeAttr('required');
}else if($(".contactorequerido option:selected").val() == true){
$('.emailrequerido').removeAttr('required');
$('.gruporequerido').removeAttr('required');
}else if($(".gruporequerido option:selected").val() == true){
$('.emailrequerido').removeAttr('required');
$('.contactorequerido').removeAttr('required');
}
})