Azamat Bagatov
Azamat Bagatov

Reputation: 289

How to get text from a text box in JS

The following code does not work

<!DOCTYPE html>
<html>
<body>

    <input type="text" id="searchTxt"/>
    <input type="button" id="run"/>
    <script>
        $(document).ready(function() { 
        $("#run").click(function(){
        var input = document.getElementById("searchTxt");
        alert(input);
        });
        });
    </script>

    </body>
    </html> 

How can I get and print the value in the text box ?

Upvotes: 0

Views: 68

Answers (2)

amouly
amouly

Reputation: 453

You have to include the jQuery JS file inside your <head> tag.

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

Upvotes: 2

Quentin Geff
Quentin Geff

Reputation: 829

.value on the element return by the getElementById function

Upvotes: 1

Related Questions