1

I have this script used with a form (Credits to: Luka [./users/6634591])

<div class="center">
<form id="search">
  <input type="text" id="keyword" />
  <button type="submit">Search</button>
</form>
</div>

<script>
document.querySelector("#search").addEventListener("submit", urlMaker)

function urlMaker(event) {
let keyword = document.querySelector("#keyword").value;
let base = "https://www.example.com/list.php?q=";
let ending = "&dhd=1&hdd=low&dtt=list";
let url;

  let url;
  event.preventDefault();
  url = base + keyword + ending;
  window.location.href = url;
}

What I would like to do is parse the url string to replace certain characters and use like url.replace = Parsed value

I am pretty skilled at building regexes. Would it be possible to parse it through a regex function at that stage? PHP is not an option as I do want this to work without apache

Like always I have googled my eyes bleeding trying to find an answer before posting.

Thank you for any input!

1 Answer 1

3

You're looking for String.replace which accepts a regular expression pattern.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.