I am interested to know how to pass a text to another function. What I'm looking to do is run a function if the condition is met... So I'm interested in running it, passing a text and at the same time knowing how to get that text in the function.
var t = document.querySelector("#texto");
var b = document.querySelector("#text_button");
b.onclick = function() {
var r = t.value;
if (r.trim() = "") {
alert("Ingresa un texto");
} else {
funcion2("Un texto aquí");
}
}
function funcion2() {
/* Recibir texto */
}
<input type="text" id="texto">
<button id="text_button">Comprobar</button>
Add a parameter to the function
funcion2()
:Also notice that you have an error in the
if
, to compare 2 equals symbols are used==
or 3 if you also want to compare the data type:Your code would look like this: