JavaScript

How to get the the value for a form element using JavaScript by ID

Written by Ian Carnaghan · 13 sec read >

If you have a text input box with ID age and you want to obtain the value for the text box via JavaScript use the JavaScript function getElementById() to get the value

Html input text box

<input type="text" name="age" id="age" value="12" />

JavaScript function

	<script type="text/javascript">
 
	var age = document.getElementById('age').value;
 
	</script>

Last Updated On March 20, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of