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

127
Views
Changing global variable javascript

I want to use global variable number = 2, but when in input form something is put I want to change value of global variable because I'm going to use it in another function so at the beginning I want number = 2 but when other value is put in input form I want number to take that value.

<form onsubmit="return timed('commands')">
    <input type="number" name="a" id="commands"><br>
</form>
   var number= 2;
   function timed(id)
   {
       number=getElementById(id).value;
       return false;
   }
   
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can add the event onchange to handle this:

<form onsubmit="return timed('commands')">
            <input type="number" name="a" id="commands" onchange="changeNumber(this.value)"/><br>
</form>

And add the function in the area:

function changeNumber(value){
            number=value
}

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!