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

116
Vistas
code rewriting in jquery based upon select selection

it 99% working, where it is failing to add the attribute of required to the input field. when a certain condition matches and also it should run of page load even if the value of select is not changed.

and if the value of select is changed then also it should run.

Here is my Javascript code try

var e = document.getElementById("StatusID");
var strUser = e.options[e.selectedIndex].value;
var _cost = document.getElementById('_total');
if(_cost.value == 0) {
    $(".Star").css('display','inline-block');
    _cost.setAttribute("required", "");
} 
else {
    $(".Star").css('display','none');
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Updated:

You should add change event for StatusID:

var e = document.getElementById("StatusID");
e.onchange = function() {
    changeHandler();
};

window.onload = function() {
    changeHandler();
};

function changeHandler() {
    var _cost = document.getElementById('_total');
    var e = document.getElementById("StatusID");
    var strUser = e.options[e.selectedIndex].value;
    if(_cost.value == 0) {
        $(".Star").css('display','inline-block');
        _cost.setAttribute("required", "");
    } 
    else {
        $(".Star").css('display','none');
    }
}

In the above (and this update), you do not need to enter the code before closing body tag.

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