0

Is it possible to rename a subpage to searched word?
So for example if you search "abc" in the search box (made using the code below)

<input name="name" type="search">
<button type="submit">search</button>

Then the site would send you to subpage called "abc"

https://examplewebsite.com/abc

EDIT:
Thanks to Justinas for telling me the answer. To get this working you need to change these 2 lines to

<input type="text" id="name">
<input type="submit" value="Search" onclick="Search(name)" />

and then create a new file <your file>.js, then just add a function

function Search(name) {
    var name = document.getElementById("name").value;
    window.location.href = name
}

Finally, you have to add a line to your website "head" so it reads the javascript file.

<script type="text/javascript" src="search.js"></script>
18o4
  • 1
  • 3
  • 1
    Yes, it's possible, but not with HTML, but Javascript: `window.location.href = 'https://example.com/' + searchWord` – Justinas May 03 '21 at 11:21
  • 1
    I think this question is a bit broad. It's not possible in pure HTML, but whether you need Javascript or a redirect with e.g. htaccess is up to the technologies you're using. – maio290 May 03 '21 at 11:21

1 Answers1

0

Not using HTML on its own, but like this

document.querySelector("form").addEventListener("submit",function(e) {
  e.preventDefault();
  location=document.getElementById("name").value;
})
<form>
<input name="name" id="name" type="search">
<button type="submit">search</button>
</form>
mplungjan
  • 169,008
  • 28
  • 173
  • 236