Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

351
Vistas
Hiding fields based on email value AND boolean yes/no field using JavaScript

I have a Microsoft Power Apps Portals page on my portal that requires a bit of customization through JavaScript. I would like to hide fields based on an email address entered, which works fine. However, when the user enters the email domain that will show some fields, I would like to apply additional formatting.

Here is the code I currently have:

$(document).ready(function () {
     $("#emailaddress1").change(onShowHideEmployeeFields);
     onShowHideEmployeeFields();
});

function onShowHideEmployeeFields() {
    var varEmail = $("#emailaddress1").val()
    //alert(varEmail)
    if (varEmail.includes("@example.org")) {
       $('#xxx_employeeid').parent().parent().show();
       $('#xxx_employeeid').prop('required', true);
       $('#xxx_employeeid').closest(".control").prev().addClass("required");
       $('#xxx_defaultfacilityid').parent().parent().show();
       $('#xxx_defaultfacilityid').prop('required', true);
       $('#xxx_defaultfacilityid').closest(".control").prev().addClass("required");
       $('#xxx_positiontitle').parent().parent().show();
       $('#xxx_officer').parent().parent().show();
       $('#xxx_officer').prop('required', true); 
       $('#xxx_officer').closest(".control").prev().addClass("required");
       $('#xxx_jopositiontitle').parent().parent().show();
    }
    else {
        $('#xxx_employeeid').parent().parent().hide();
        $('#xxx_defaultfacilityid').parent().parent().hide();
        $('xxx_defaultfacilityid_label').parent().parent().hide();
        $('xxx_positiontitle_label').parent().parent().hide();
        $('#xxx_positiontitle').parent().parent().hide();
        $('#xxx_officer').parent().parent().hide();
        $('#xxx_jopositiontitle').parent().parent().hide();
    }
}

The code works fine, however, I want to extend the code by showing the JO Position Title IF the Officer field has been marked as 'Yes' (it is a boolean yes/no radio checkbox field).

I've tried testing this component separately using the below code:

function onShowHideEmployeeFields() {
$('xxx_officer').change(function () {
    var varJO = $("$xxx_officer").val();
    //alert(varJO)
    if (varJO === 'Yes') {
    $('xxx_jopositiontitle').parent().parent().show();
    }
    else {
    $('xxx_jopositiontitle').parent().parent().hide();
    }
})
}

This code doesn't seem to do anything. Any thoughts on this issue?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

AFAICT your question boils down to how can I check if a checkbox is checked?. The code you tried is on the right track, but that's not how you get a checkbox's state. A quick search turns up many many examples:

$('xxx_officer').change(function () {
    var varJO = $("$xxx_officer").prop('checked');

    if (varJO) {
        $('xxx_jopositiontitle').parent().parent().show();
    } else {
        $('xxx_jopositiontitle').parent().parent().hide();
    }
});

There are many, many examples of this here on SO, and I've voted to close this question as a duplicate.

  • How do I check whether a checkbox is checked in jQuery?
  • Get checkbox value in jQuery
  • get current state of check box jquery
  • Check if checkbox is checked with jQuery
  • Get checkbox selected state with JQuery
  • ...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda