Sandeep Rawat Sandeep Rawat - 1 month ago 7
Javascript Question

On form submit using <span> button redirect to new site

I need to submit the below form and redirect the page to another site to display the search result as per the input searchString.

<a href="#" class="button search">
<span class="spanclass"></span>
<input class="expand" name="searchString" type="text">
<span id="searchButton" class="search icon-small open-btn"></span>
</a>


I am wondering how can I process it either using javascript, jquery or ajax. Please provide your valuable inputs. As I have the submit button as span, I am not sure how I can use it to submit the form. Thanks folks in advance for the valuable information.

Answer

inline js solution

<span id="searchButton" class="search icon-small open-btn" onclick="document.forms['form-name'].submit();"></span>

but since you also included jquery tag for your question :)

$(document).ready(function(){
   $('#searchButton').click(function(){
     $("#form-id").submit();
   });
})