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);
};
有帮助吗?

解决方案

use this

function confirmFunc() {
var name = document.getElementById("namebox").value;
confirm("Please confirm that the following name is correct: " +name);
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top