Im trying to extract the values of my inputs. Im using this inputs in a JavaScript. Im using the onclick event on an input type button called thebutton and I want to extract the values in a function called data. The inputs are print in a div called formulary and I want to print the input values in a div called results. When I run it, the three values are print as undefined. So this is my current code:
<script>
document.getElementById("fomulary").innerHTML+="<br>Data:<br><br> <form><input id='name' type='text' placeholder='Name'<br><br><input id='address' type='text' placeholder='Address'<br> <br> <input id='tel' type='tel' placeholder='Phone number'><br> <input onclick='data()' type='button' id='thebutton' value='Send'></button> </form>";
var name=document.getElementById("name").value;
var address=document.getElementById("address").value;
var tel=document.getElementById("tel").value;
function data(name, address, tel){
document.getElementById("results").innerHTML=name+" "+address+" "+tel;
}
<script>
Thank you.