Question

I am trying to get a confirmation box to display my input data from a textbox, but instead of whatever I put in, the confirmation box displays "null" where the input is supposed to be. Please help. I tried adding .val() to name in the confirmation box, but no luck. JSFiddle

HTML:

First Name: <input type="text" id="namebox">
<input type="submit" id="submitbutton" onClick="confirmFunc()">

JS:

function confirmFunc() {
    var name = document.getElementById("#namebox");
    confirm("Please confirm that the following name is correct: " +name);
};
Was it helpful?

Solution

use this

function confirmFunc() {
var name = document.getElementById("namebox").value;
confirm("Please confirm that the following name is correct: " +name);
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top