Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda