I want to suggest a variable which contain data by user from input section and store it into my variable so how I can do this in JavaScript? I suggest a = .... but that does not work as expected
let a = document.getElementById("link");
function lol() {
document.getElementById("print").innerHTML = `a`;
}
<input type="text" id="link" name="link">
<button id="btn" onclick="lol()">Upload Video</button>
<p id="print"></p>
CodePudding user response:
You have to pass event and it's target value not only make reference from input to paragraph.
Adrian
CodePudding user response:
function lol() {
document.getElementById("print").innerText = a.value;
}
Use innerText instead of innerHtml to avoid html syntax passed through that input.
If you put variable name in parentheses it will treat it as text and not variable.
And a is input field with many options, to access value you use a.value