0

Alert with HTML Element

How can I create an Alert Writing Hello+username (Input with id="username" from HTML)

23rd Feb 2017, 11:09 PM
Phoenix24
4 odpowiedzi
+ 3
You need to handle some interactivity, by adding at least a button ( or a link, or something else ) to validate user entry ( and showing the alert box ), as you can't automatize the opening of the box ( where, when, and how? ): <input id="username" type="text"> <input type="button" value="ok" onclick="alert('Hello '+document.getElementById('username').value);">
24th Feb 2017, 10:20 PM
visph
visph - avatar
+ 2
write some username in text field
24th Feb 2017, 11:04 AM
Finochek Kuvachic
Finochek Kuvachic - avatar
0
var user=document.getElementById('username').value; alert("Hello " + user);
24th Feb 2017, 12:41 AM
Finochek Kuvachic
Finochek Kuvachic - avatar
0
okay, what should i do in the HTML document to define the .value ?
24th Feb 2017, 6:28 AM
Phoenix24