0

I work on an application and I want to connect the front end (JavaScript) with the back end (Java). I have an input in HTML. When a user inputs something, by clicking on a button, I want to get that value in Java, so I can perform some actions on it. How can I do this? Thank you!

<input type="text" id="input" placeholder="Input...">
<button type="button" id="button" onclick="loadResults()">Search</button>
1
  • 1
    You have to serialize the content you want to send (usually JSON, but it could also be something else) and then send it to the backend by using XMLHttpRequest or any wrapper that your framework provides Commented Dec 14, 2020 at 18:33

1 Answer 1

1

the easiest way I can see is getting the value from the input using the id property, like so:

const inputValue = document.getElementById("input").value

and then it is expected that you have some kind of API setup on your java backend, if so you can use the fetch built in function to make a HTTP request to you java backend https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.