Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Manipulate the Text element in Html by A Variable whose value is given by the user?

I am trying to Manipulate the Text with id ‘varname’ (Spartans) with the value inputted in the form saved as a variable ‘input’

<div class="middle">
    <h2 class="greet" id="demo">Welcome Back,&nbsp; <span id="varname">Spartan</span></h2>
     <div class="form">
    <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>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use <input type="button"> instead of <input type="submit">

https://jsfiddle.net/yt0kgnqe/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading