Combining Strings for URL

Heyo, I’ve done a lot of looking on other forums and sites, but I can’t find what I’m looking for. I’m trying to make a search bare that simple takes the URL and then ads .HTML to it.

Example:

Textbox: yes

You click a button and then it’d redirect to https://example.com/yes.html

I’ve done this in js, but can’t figure it out in HTML. Let me know if you know how to do this :slight_smile:

just use javascript in your html. when the button is clicked fire a function and redirect the user.

1 Like

Unfortunately you can’t use plain HTML for that. However here is example how you could do it in JavaScript combined with Html.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Example</title>
    <script defer>
      var SearchInput = document.getElementById("search-input");
      SearchInput.addEventListener("change", function() {
        window.location.replace(window.location + SearchInput.value + ".html");
      });
    </script>
  </head>  
  <body>
    <input type="text" placeholder="Search Here" id="search-input" />
  </body>
</html>

Hopefully it did help, make sure to put this into Html file. If you need explanation for certain parts of the code, just ask :upside_down_face:

2 Likes