jquery - window.location.href not working -


my website http://www.collegeanswerz.com/. i'm using rails. code searching colleges. want user able type in colleges name, click enter, , taken url, rather seeing search results (if user types in name properly. if not want show search results). i'm using "a" , "stackoverflow.com" placeholders while try work.

i'm using window.location.href based on this: how redirect webpage in javascript/jquery?

javascript

$("#search_text").submit(function() {     if ($("#search_field").val() == "a")     {         window.location.href = "http://stackoverflow.com";         alert('worked');     } }); 

layout file

<%= form_tag("/search", :method => 'get', :id => 'search_text', :class => 'form_search') -%>      <div id="search"> <%= search_field_tag :search, params[:search], :placeholder => 'enter college', :id => "search_field", :class => 'input-medium search-query' %></div>  <% end -%> 

static_pages_controller.rb

def search   @colleges = college.search(params[:search]) end 

the alert working, tells me things inside if statement should being executed. it's taking me normal search results instead of stackoverflow.com. why this?

the browser still submitting form after code runs.

add return false; handler prevent that.


Popular posts from this blog

Apache NiFi ExecuteScript: Groovy script to replace Json values via a mapping file -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -