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.

[your input field].value

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.