Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Monday, December 28, 2015

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

On form submit using 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.

                      

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 by Nishad K Ahamed for On form submit using button redirect to new site


attach an onlclick function to the span using jquery, and submit the form inside the function

script:

$(document).ready(function(){  $('#searchButton').click(function(){  $("form").submit()//assuming you have a form tag with an action specified  })  })  

Answer by Sreepathy Sp for On form submit using button redirect to new site


           var SearchedItem=$(".expand).text();                    $.ajax({              type: "POST",              async: false,              dataType: 'json',              url: "/MyController/Index",              contentType: 'application/json',              // processData: false,              data: JSON.stringify({ SearchedItem: SearchedItem}),              success: function (data) {                }          });  

Answer by gurvinder372 for On form submit using button redirect to new site


inline js solution

  

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

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

Answer by synthet1c for On form submit using button redirect to new site


The code doesn't work on stack because of the Same Origin Policy in the iframe

$(function(){    var searchString = $('.expand'),        searchButton = $('#searchButton');        searchButton.on('click', function(e){      window.location.href = searchString.val();    });  })
* {    box-sizing: border-box;  }    .search-box {    width: 300px;    height: 2em;  }    .expand {    width: 260px;    height: 100%;    float: left;  }    .search {    width: 40px;    height: 100%;    background: teal;    float: left;    cursor: pointer;  }
  

Answer by shishir for On form submit using button redirect to new site


Just add an onclick event to the element:

  

You can also but this in a JavaScript block.

  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.