View Full Version : Resolved javascript get value of input field

07-23-2011, 12:56 PM
I'm new in web-development. I've searched it but it's not found. I make a input then how i get value of it for javascript value?

Philip M
07-23-2011, 01:16 PM
This is pretty fundamenatal and ought to be covered in any textbook. Assuming that your input is a textbox:-

<input type = "text" id = "txt1">
<input type = "button" value = "Click to get value entered into textbox" onclick = "getValue()">

<script type = "text/javascript">
function getValue() {
var val = document.getElementById("txt1").value;
alert (val);


The function can of course be called in different ways.

All this talk about ripping people's heads off - that going below the belt, really. - Presenter, BBC Radio 5 Live

07-23-2011, 01:27 PM
sure, Is ".value" used for only numbers?

07-23-2011, 03:48 PM
sure, Is ".value" used for only numbers?

it probably took you twice as long to type that question as it would have to test it yourself :confused: