Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an input from html file.
and i have an js file.

but when i hit the "Submit" button, there's a error. why?

the code:

html:

<form method="" action="">
<input autofocus type="text" name="mission" id="mission" class="" placeholder="" required >
<label id="" for="mission"> name: </label>

<button id="submit" type="submit">submit</button>

</form>


js:

var button = document.querySelector("#submit");

	button.addEventListener("click", function(){
	var firstAns = document.getElementById("#mission").value;
	console.log(firstAns);  //there's an error

});


What I have tried:

read some articles but i have got nothing.
Posted
Updated 16-Feb-19 5:22am

1 solution

Just put mission instead of #mission. getElementById does not want the #.
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 16-Feb-19 10:18am    
5ed.
Patrice T 16-Feb-19 13:08pm    
Have a look at S2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900