Read Input form HTML Form Element using JS

This post will help you to fetch the value from any input tag in the FORM Element.
The below code fetches the value of the text field when submit button is clicked and displays an JS alert counting the number of characters of the input string.

Screenshots:


The Code:
<script type="text/javascript">
function callMe()
{
 var nam=document.getElementById("myText").value;
 
 alert("Your name is "+nam+" and it has "+nam.length+" Chars");
}
</script>
<form onsubmit="callMe()">
 <input type="text" placeholder="Enter your name!" id="myText"/><br/><br/>
 <input type="submit" value="Submit"> 
</form>

Found any suggestions ?
Comment them here !

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Bit Stuffing Code Implementation in Java

Hackerrank Modified Kaprekar Numbers Solution