0

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>

6/11/2018 8:59:35 AM

Alieldien

4 Answers

New Answer

+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

+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;

+1

What is car for . can you write for me the correct code

+1

Thank You Akash Pal