I already connected the html with js and I get the data from a form when the onclick is activated but since I save each data that I receive to use it later, how do I get the data out of the function without having problems:
var getData = () => { let name = document.getElementById("name").value; let age = document.getElementById("age").value; if (name == "") { document.getElementById("name").focus(); } else { if (age == "") { document.getElementById("age").focus(); } else { console.log(name + " " + age); document.getElementById("name").value = ""; document.getElementById("age").value = ""; document.getElementById("name").focus(); } } };
Advertisement
Answer
You should create an external variable to save the data you want, when the function you are using finishes, the data in it “disapears”. So, in order to save it, you should create an external variable.
Anyways, should be good to know a bit more of the problem that you are facing with.