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") {}
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) {}
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
}
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.