0

How can I get the value of an input field in Javascript? For example, someone types somehing into an input field and I want them to press a button to in turn, store the data in a JS variable. I believe there is such a thing as .value, but it doesn't work. Nothing, so far, has. Please help.

3
Contributors
2
Replies
16
Views
4 Years
Discussion Span
Last Post by Bachu
0

Hai;

Try this..

<input type="text" name="txtfield" id="txtfield" value="" />
<input type="button" onclick="getValue()"  value="Get Value"/>

<script type="text/javascript">
function getValue() {
    alert(document.getElementById("txtfield").value);
}
</script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.