Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 771
Sandeep Rawat Avatar asked Sep 26 '22 19:09

Sandeep Rawat


People also ask

How do you redirect to another page in JS on submit?

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.

How do I submit a form on a click of hyperlinks?

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.

How do I add a hyperlink to a submit button?

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.

What is the difference between input type submit and button type submit?

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).


1 Answers

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();
   });
})
like image 136
gurvinder372 Avatar answered Sep 30 '22 06:09

gurvinder372