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

408
Views
When i click button the value is not sending in js?

I make mini app to find factorial. When i click button and get number in js it is not showing any thing. This is my script.js

function factorial() {
let number = document.getElementById("number")
console.log(number);
for (let i = number - 1; i >= 1; i++) {
    number = i * number
    console.log(number);
}
console.log(number);
return number;
}

this is my index.html

<input type="text" name="number" class="number" id="number">
<button onclick="factorial()" class="btn btn-primary " style="padding-right: 160px;padding-left: 160px">Find</button>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Like this for example:

function factorial() {
  let number = document.getElementById("number").value
  console.log(number);
  for (let i = number - 1; i >= 1; i--) {
      number = i * number
  }
  document.getElementById("result").innerHTML = number
}
<input type="text" name="number" class="number" id="number">
<button onclick="factorial()" class="btn btn-primary " style="padding-right: 160px;padding-left: 160px">Find</button>
<h3 id="result"></h3>

about 4 years ago · Juan Pablo Isaza Report

0

There is a property called .value. This will return the inner value of inputs (You can try it). After you achieved the value of the input, then you can run your statement.

Read about .textContent here.

Read about .querySelector() here.

Tip: Don't ever use onclick(). No one uses it anymore, use .addEventListener() instead.

function factorial() {

// Edited here
let number = document.getElementById("number").value;
console.log(number);
for (let i = number - 1; i >= 1; i++) {
    number = i * number
    console.log(number);
}

  // As you wanted to put the result in the html file
  document.querySelector('h1').textContent += number;
}
<input type="text" name="number" class="number" id="number">
<button onclick="factorial()" class="btn btn-primary " style="padding-right: 160px;padding-left: 160px">Find</button>

<h1>Result: </h1>

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!