function myFunction()
{
alert(document.getElementById("myname").value+','+document.getElementById("myphone")+','+document.getElementById("mycountry")+','+document.getElementById("myemail"));
}
-
Can you please add more details?Aastha B– Aastha B2022-09-03 16:32:50 +00:00Commented Sep 3, 2022 at 16:32
-
get user input from html through input tag and i need to display those values in pop up alert boxVIJAYARAJ– VIJAYARAJ2022-09-03 16:50:21 +00:00Commented Sep 3, 2022 at 16:50
Add a comment
|
1 Answer
it seems pretty straightforward to me
I just refactor a bit your function
function myFunction() {
const message = ['myname', 'myphone', 'mycountry', 'myemail']
.map(id => document.getElementById(id).value)
.join(',')
alert(message);
}
<div>
<input id="myname" placeholder="myname" />
<input id="myphone" placeholder="myphone" />
<input id="mycountry" placeholder="mycountry" />
<input id="myemail" placeholder="myemail" />
</div>
<div>
<button onclick="myFunction()">Show alert</button>
</div>