JSFiddle - React, Tailwind, and code Playground

by Vetrivel Samidurai

HTML

<form name="reg_frm" method="post">

First Name: <input type="text" name="fname" class="myclass" id="myText" value="CODEFORBEGINNER">

<p>Click the button to display the value of the value attribute of the text field.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>
</form>

JavaScript

function myFunction() {
   
    /*var x = document.getElementById("myText").value;
    var x = document.getElementsByName("fname")[0].value;
    var x = document.getElementsByTagName("input")[0].value;
    var x = document.getElementsByClassName("myclass")[0].value;*/
     var x = document.reg_frm.fname.value;
    document.getElementById("demo").innerHTML = x;
		return false;
}