Andrew O Neill Andrew O Neill - 2 years ago 59
Javascript Question

How to access a user input email without changing page in Javascript

So I want the user to write in an email in the input field, and then I want to take that input when the button is clicked, without changing page, as it ruins my routes.

<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Add Navigators Email so they can access the Session">

<button type="button" onclick="addNav()" class="btn btn-success">Add to Session</button><br>

I need to get the input of a user without changing page using solely javascript.
Is this possible?

Answer Source

You have to find the element by it's id and then get it's value:

email_input = document.getElementById("email");

Working example:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download