How to get value from input box in JavaScript?

In this post, I am going to provide you a useful JavaScript code snippet. Here I am going to tell you how you can take the value of an input box.

To do it take an input text box for example that is given below:

<input name="searchBox" type="text" maxlength="300" id="searchBox" />

The above form has the ID “searchBox”. Using this unique ID, you can retrieve the input text value.

Below is the given JavaScript code which will retrieve the input text box value:

Method 1:


Method 2:


Method 3:

This method is going to use jQuery. If you are using jQuery framework, then you can get the text input value using the below jQuery code:



2 responses to “How to get value from input box in JavaScript?”

  1. Tatiana says:

    > The above form has the ID “searchBox”.
    The ID is “searchText”.

Leave a Reply

Your email address will not be published. Required fields are marked *