Как заменить + на - в поисковом URL - PullRequest
1 голос
/ 19 января 2020

Я хочу создать поиск, который выполняет поиск на каком-либо другом веб-сайте с моего веб-сайта. Проблема в том, что используется другой веб-сайт - вместо +, например: https://somewebsite.com/?search=example-search-query, но когда я использую этот код:

<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>

Это, конечно, добавляет + вместо - любая помощь будет оценена, спасибо!

1 Ответ

2 голосов
/ 19 января 2020

Используйте функцию, которая связана с действием отправки

<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>
...