I am trying to Manipulate the Text with id 'varname' (Spartans) with the value inputted in the form saved as a variable 'input'
<div >
<h2 id="demo">Welcome Back, <span id="varname">Spartan</span></h2>
<div >
<form>
<label for="Name">Enter Your Name</label>
<input type="text" id="Name">
<input type="submit" value="Submit" onclick="myFunction()">
</form>
</div>
<script>
function myFunction(){
var input= document.getElementById("Name").value;
document.getElementById("varname").innerHTML = input;
}
</script>
CodePudding user response:
Use <input type="button">
instead of <input type="submit">