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

284
Views
disable elements when value = 1, enable them when value > 1

Using javascript only I am trying to say if cycn = 1, disable input element with id="prevdl"

if cycn > 1, then do not disable element with id="prevdl", and in both cases preview the value of cycn in the <p> with id="transit"

but condition after if (cycn = 1) is executed no matter what. And the one after else is not seen at all

HTML

<label for="cyclecount">Cycle Count:</label>
<input type="number" id="cyccnt" name="cyclecount" placeholder="Today's cycle number" min="1" max="6" autocomplete="off" value=""><br><br>

<p id="transit"></p>

<label for="previousdoseLevel">Previous Dose Level:</label>
<input type="number" id="prevdl" name="previousdoseLevel" placeholder="Insert Previous Dose Level" autocomplete="off" value=""><br><br>

Javascript

var cyc = document.getElementById("cyccnt");
var cycn = Number(cyc.value);
document.getElementById("cyccnt").oninput = function (e) { 
    if (cycn = 1) {
        document.getElementById("prevdl").disabled = true;
        document.getElementById("transit").innerHTML = cycn;   
    } else if (cycn >1) {
        document.getElementById("prevdl").disabled = false; 
        document.getElementById("transit").innerHTML = cycn;    
    }
    e.preventDefault(e);
}

please help and thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

use double ==

if (cycn == 1) {
  document.getElementById("prevdl").disabled = true;
  document.getElementById("transit").innerHTML = cycn;   
}

and take the value from the event instead.

document.getElementById("cyccnt").oninput = function (e) {
  e.preventDefault();
  var value = e.target.value
  document.getElementById("transit").innerHTML = value;    
  if (value && +value == 1) {
    document.getElementById("prevdl").disabled = true;
  } else {
    document.getElementById("prevdl").disabled = false; 
  }
}
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!