Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!