'Get current value of input HTML JS [closed]

I have an html page that requires getting the value of an input when a button is pressed so it can be used as a variable in a link. For example, my website would detect "word" being written in the input and would redirect to the link "google.com/word" when the button is clicked. Thanks for any help in advance!

HTML Code:

<td><input value="Input text Here..."></input></td>
<td><a href='https://example.com/test/VALUEFROMINPUTHERE'><button id="click">Click this Button</button></a></td>


Solution 1:[1]

In this code, when the a tag is clicked, it triggers a JS function that grabs the value of the input with the id "value" and opens thee link with by concatenating it's value to the end of the URL with the window.open() function.

<input type="text" placeholder="Enter Text" id="value" />
<a href="#" onClick="openLink()">Click Me</a>
<script>
function openLink() {
  let value = document.getElementById("value").value
  window.open(`https://www.example.com/${value}`)
}
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1