? I am working on a search engine and I have a really serious problem with the GET and ...">

Can I submit form values ​​using <input type = "button" / ">?

I am working on a search engine and I have a really serious problem with the GET and POST methods.

Im uses <input type="button" /> so that the page does not refresh every time the button is clicked.

After clicking the button, I show the result (google_map, monumet picture, specs).

Now the problem is that I want to send and show the form values ​​+ result (google_map, monumet picture, specs) by clicking this button.

This is a problem because <input type="button" /> does not pass form values, and I'm really stuck.

+4
source share
2 answers

Of course, here's a working example for you:

index.php

 <!DOCTYPE html> <html> <head> <title>Working Example</title> </head> <body> <form id="search-form"> <input type="text" name="text1" id="text1" value=""><br> <input type="text" name="text2" id="text2" value=""><br> <input type="text" name="text3" id="text3" value=""><br> <input type="button" id="search-button" name="search-button" value="search"> </form> <div id="response"></div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('#search-button').click(function(){ $.ajax( { type: "GET", url: 'response.php', data: $('#search-form').serialize(), success: function(response) { $('#response').html(response); } } ); }); }); </script> </body> </html> 

response.php

 <?php echo "text1: " . $_GET['text1'] . "<br>"; echo "text2: " . $_GET['text2'] . "<br>"; echo "text3: " . $_GET['text3'] . "<br>"; echo "your response ..."; 

In the response, you return your answer, plus the form fields.

+3
source
 onClick="document.getElementById('FormName').submit();" 
+1
source

Source: https://habr.com/ru/post/1502280/


All Articles