Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda