+ 1

welcome alert

This is my code , when i write something on the input and i click it keeps saying for me welcome undefined. How can i make say welcome and what i write. <!Doctype html> <html> <body> <button id = "btn">Click</button> <input type = text id = "input"> <script> var inp document.getElementById("input"); function inpu() { inp = document.getElementById("input"); } var mybtn; function init() { mybtn = document.getElementById("btn"); mybtn.onclick = function(){ alert("welcome " + inp); } } window.addEventListener("DOMContentLoaded" , init); </script> </body> </html>

11th Jun 2018, 8:59 AM
Alieldien
Alieldien - avatar
4 odpowiedzi
+ 5
Alieldien I have a made a simple program for you. Maybe you like it. I will also make one more from your code. https://code.sololearn.com/WXvt48g1cVpL/?ref=app
11th Jun 2018, 9:24 AM
Akash Pal
Akash Pal - avatar
+ 2
Alieldien First of all the in the input section of the HTML, you have not included type text into " " . You can do it like type="text". Second mistake you can't get a variable from a function to another function. It will cause an error. Third, you have not got the value of input in the inp variable. You can do it like this. var inp = document.getElementById('input').value;
11th Jun 2018, 9:11 AM
Akash Pal
Akash Pal - avatar
+ 1
What is car for . can you write for me the correct code
11th Jun 2018, 9:16 AM
Alieldien
Alieldien - avatar
+ 1
Thank You Akash Pal
11th Jun 2018, 9:30 AM
Alieldien
Alieldien - avatar