Anraiki
Anraiki

Reputation: 796

Take User Input Value and Redirect

Basically, I have a search box. Once clicked, the value within the search box would be sanitize and then redirects as a Get Var rather than a Post.

I have one method of taking the User's Input value and redirecting to what they want to search (But it turns into a Post Method).

I want to achieve the following:

  1. User Input Value: "I am Searching"
  2. User/Web Client (Javascript) takes User Input Value, sanitize it for URL, and redirects.
  3. User is taken to: example.com/search/i-am-searching

Rather than:

  1. User Input Value: "I am Searching"
  2. Server Side takes Post Value of "I am Searching" then redirects.
  3. User is taken to: example.com/search/i-am-searching

Upvotes: 1

Views: 540

Answers (2)

Nervo Verdezoto
Nervo Verdezoto

Reputation: 511

A good idea could be to check how to use window.location Object. You can check this tutorial: How to get url parts in javascript and you can learn:

  • How to obtaing the URL from the window.location object
  • How to change the current location using window.location.href and window.location.reload
  • How to split and rebuild URLs using an array and string splitting functions

In addition, you can check document.URL and document.referrer

Upvotes: 1

user370306
user370306

Reputation:

With:

var value = document.getElementById('id_of_field').value; you get the value of the field and with

window.location = "http://example.com/search/" + value;

Upvotes: 1

Related Questions