4

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

Im using an <input type="button" /> to avoid page from refreshing every time im pressing the button.

After button is pressed I'm showing a result (google_map, monumet picture, specs).

The problem now is that I want to submit and show form values + result (google_map, monumet picture, specs) by pressing this button.

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

4
  • 1
    use javascript document.getElementById("myform").submit(); Commented Sep 15, 2013 at 15:13
  • <input id="slide" onMouseUp="getScriptPage('count_display','text_content','1')" type="button" style="font-family:cursive;border-radius:10px 10px 10px 10px;background-color:brown;color:white;font-size:14pt;" value="Search now" name="filter" /> <BR/><BR/> Commented Sep 15, 2013 at 15:18
  • the problem is that i already using javascript if button isset onMouseUp="getScriptPage('count_display','text_content','1')" Commented Sep 15, 2013 at 15:18
  • is it possible to call to javascript functions the same time ? onMouseUp="getScriptPage('count_display','text_content','1'); script_page2(.....);" Commented Sep 15, 2013 at 15:20

2 Answers 2

3

Sure, here is 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 whatever your response is, plus the form fields.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks arielcr,can you please post me a working example with this code you just post to me? coz i tried my self and i think im doing something wrong
I edit the answer with a working example. I forgat to tell you that you can use whatever event for the ajax response, I used the click event for the button as a example. Hope it helps!
thank you so much you are the best...you save my day for sure ...:-)
1
onClick="document.getElementById('FormName').submit();"

2 Comments

im already using onMouseUp="getScriptPage('count_display','text_content','1')"......Can i use onclick and onMouseUp in the same input?
@AntreasApostolou It would take less to to try it yourself then writing this comment...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.