IdioticDev
IdioticDev

Reputation: 33

How to replace + with - in search URL

I want to create a search which searches some other website from my website, The problem is that other website is uses - instead of + for example: https://somewebsite.com/?search=example-search-query but when I use this code:

<form class="example" method="get" action="https://europixhd.io/svop2/zznewsrv4" style="margin:auto;max-width:300px">
  <input type="text" placeholder="Movie Name Here..." name="search">
  <button type="submit"><i class="fa fa-play"></i></button>
</form>

It of course adds a + instead of a - any help would be appreciated, Thanks!

Upvotes: 1

Views: 67

Answers (1)

O.Rares
O.Rares

Reputation: 1061

Use a function that is binded to the submit action

<html>
<form class="example" method="get" action="" id="formID" style="margin:auto;max-width:300px">
  <input type="text" placeholder="Movie Name Here..." name="search" id="search">
  <button type="submit" ><i class="fa fa-play"></i></button>
</form>
</html>
<script>
var form = document.querySelector('#formID');
form.addEventListener('submit', searchUpdater);

function searchUpdater() {
  var text = document.getElementById("search").value.replace(" ", "-"); 
  document.getElementById("search").value = text;
  return true;
}
</script>

Upvotes: 2

Related Questions