문제

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