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.
If you want to redirect to another page after form submit html, Then you have to provide/Sign the Other pages path inside HTML Form tag's ACTION Attribute. Which will POST/Send your Form data to that Location and Open/Redirect your Users to That Given Web Page.
In the body tag, created an HTML form and specify the id, method, and action of the form. In the form, specify an anchor tag with an event onclick. Create a function for JavaScript that will get executed when the link is clicked. When we click on the link, the function submitForm() will get executed.
You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.
A 'button' is just that, a button, to which you can add additional functionality using Javascript. A 'submit' input type has the default functionality of submitting the form it's placed in (though, of course, you can still add additional functionality using Javascript).
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();
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With