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

165
Views
How to pass javascript function variable to a differet javascript function?

I want to use the 'output.innerHTML' to the 'generatePassword' function.

function sliderControl() {
    var slider = document.getElementById("slider");
    var output = document.getElementById("output");
    output.innerHTML = slider.value;
    slider.oninput = function() {
        output.innerHTML = this.value;
    };
}
sliderControl();

function generatePassword(length = "I WANT TO USE THAT VARIABLE HERE") {}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can return output.innerHTML

function sliderControl() {
    var slider = document.getElementById("slider");
    var output = document.getElementById("output");

    slider.oninput = function() {
        output.innerHTML = this.value;
    };
    output.innerHTML = slider.value;
    return output.innerHTML;
 }
const val = sliderControl();

function generatePassword(val) {}
about 4 years ago · Juan Pablo Isaza Report

0

You can add a new variable.

function sliderControl() {
var slider = document.getElementById("slider");
  var output = document.getElementById("output");
  output.innerHTML = slider.value;
  slider.oninput = function () {
    output.innerHTML = this.value;
    return output.innerHTML;
  };
}
var yourVariable = sliderControl();

function generatePassword(yourVariable) {
    // do the thing with yourVariable
}
about 4 years ago · Juan Pablo Isaza Report

0

You could use the output.innerHTML like you have set it.

function sliderControl() {
  let slider = document.getElementById("slider");
  let output = document.getElementById("output");
  output.innerHTML = slider.value;
  slider.oninput = function () {
    output.innerHTML = this.value;
  };
}
sliderControl();

function generatePassword() {
  let length = document.getElementById("output").innerHTML;
}

I would also recommend to use let instead of var inside closures and functions. As var might cause unexpected side effects, as it can change the value of a already declared variable of the same name outside the functions/closure.

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!