0

Hi everyone...


Well i do have a mysql query in one php page(php_1) & I want to submit the variables to the query in different php page(php_2) via form action but how am I supposed to do it without redirecting to php_1..

All I need is to post the data to the first php page query so that It performs some action over there & thats all... So hoping sumone who knows ajax might helpme out with a sample code or point me in the right direction...

Thanks,

php_1 page :-

$query = ("SELECT * FROM state4 WHERE (LONG_HI<'".$_POST['Ymax']."')");

php_2 page:-

Ymax<input type="text" name="Ymax" size="15">
	      <input type=SUBMIT name="submit" VALUE="Submit"></td>
7
Contributors
6
Replies
16
Views
6 Years
Discussion Span
Last Post by Bachu
0

I dont know much about php, but first change the submit button to a normal button

<input type="button" name="submit" VALUE="Submit" onclick="sendInfo()">

and use the onclick property to call your ajax function, there are many examples of a simple ajax function on the internet.

0

Hi!
This is the codes:
(page php_2):

<html>
<script type="text/javascript">
function sendData(){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var Ymax=document.getElementById('Ymax').value;
result=xmlhttp.responseText;
//in the html element <div id="forResult"></div>
//will be writen what you write with "echo" in your php file
//in this example, "Thank you for submiting Ymax"
document.getElementById('forResult').innerHTML=result;
}
}
xmlhttp.open("GET","php_1.php?Ymax="+Ymax,true);
xmlhttp.send();
}
</script>
<body>
Ymax: <input type="text" id="Ymax" size="15"><br>
<input type="button" value="Submit" onclick="sendData()">
<div id="forResult"></div>
</body>
</html>

php_1:

<?php
$Ymax=$_GET['Ymax'];
//......
//query.....
echo "Thank you for submiting Ymax";
?>

Edited by ivan3510: n/a

0

The var Ymax in line 11 is out of scope for xmlhttp.open in line 19.
Hence it uses in "Ymax" input box in line 24 and prints [object HTMLInputElement]

0

I would use JQuery:

    <script>
        $(function() // on DOM loaded
            $("#btnSubmit").click(function(){ // Click handler 
                var yMax = $("#txtYmax").val(); // Get YMax value
                $.ajax(
                    'MyPhpPage.php', // Page to handle the request
                    { yMax : yMax }, // Parameters to send
                    function(result) { // Function executed when the request is completed
                        $("#forResult").html(result);
                    },
                    function(erro) { // Function executed when the request throws an error
                        //do something
                    }
                );
            });
        });
    </script>
    <body>
        Ymax: <input type="text" id="txtYmax" size="15">
              <input type="button" value="Submit" id="btnSubmit">
        <div id="forResult"></div>
</body>
0
Ymax<input type="text" name="Ymax" id="Ymax" size="15">
          <input type="button" name="submit" class="submitBtn" VALUE="Submit">
<script  type="text/javascript">
$(function(){
    $('.submitBtn').click(function(){

        $.post('otherPhpPage.php',{Ymax: $('#Ymax').val()},function(data){
            alert(data);
        });
    });
});
</script>

<!--##########  In otherPhpPage.php ########  -->

<?php
echo $yMax=$_REQUEST['Ymax']; 
?>

Result of this code will show an alert with your entered Ymas value

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.