Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

google search input javascript

(function(){
    var googleBox = document.getElementById("googleBox"),
        searchButton = document.getElementById("searchButton");

  searchButton.addEventListener("click", function(){
    var userInput = googleBox.value,
        regex_google = new RegExp('google(.*)');

    if(userInput.match(/^([w-]+)/)[1].toLowerCase() === "google"){ // matches the first word in the string, which should be 'google'

      window.open('https://www.google.com/search?q=' + userInput.match(regex_google)[1].trim());
    }
  });
})();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #google #search #input #javascript
ADD COMMENT
Topic
Name
5+4 =