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.

Recommended Answers

[your input field].value

Jump to Post

All 2 Replies

[your input field].value


Try this..

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

<script type="text/javascript">
function getValue() {
Be a part of the DaniWeb community

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