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

231
Views
how can i control the submit button with JS function in html form

html code :

<input id="Degree" name="Degree" type="number" size="10">
<select id="year" name="date" onchange="jsyear(this.value);">
  <option value="2000"> 2000 </option>
  <option value="2001"> 2001 </option>
  <option value="2002"> 2002 </option>
  <option selected> 2003 </option>
  <option> 2004 </option>
  <option> 2005 </option>
</select>

and the JavaScript code :

function jsyear(value) {
  if (value < 2003) {
    alert("You are too old ");
  }

}

let degreeInput = document.getElementById('Degree');
let delayTimer;

degreeInput.oninput = (e) => {
  clearTimeout(delayTimer);
  delayTimer = setTimeout(() => {
    if (e.target.value < 73) {
      alert(" your degree is less than required ");
    }
  }, 1050);
};

i want to prevent from submitting it unless all these function is true , if it's false then it cant submit . hlep me guys plz

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

0

You only need to add a button

const button = document.getElementById("submit");
const degree = document.getElementById("Degree");
const year = document.getElementById("year");

function check(){
  if (year.value < 2003){
    alert("You are too old");
    button.disabled = true;
  } else if (degree.value < 73){
    alert("Your degree is less than required");
    button.disabled = true;
  } else {
    button.disabled = false;
  }
}

degree.onchange = check;
year.onchange = check;
<form id="myform" action="#">
<input id="Degree" name="Degree" type="number" size="10">
<select id="year" name="date">
  <option value="2000"> 2000 </option>
  <option value="2001"> 2001 </option>
  <option value="2002"> 2002 </option>
  <option selected> 2003 </option>
  <option> 2004 </option>
  <option> 2005 </option>
</select>
<input type="submit" id="submit" value="Check" disabled>
</form>

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!