获取文本框值在同一页面上但不同的php文件

获取文本框值在同一页面上但不同的php文件

问题描述:

I have this main page that loads another php file on onchange event of the dropdown. I use this to load the page:

function get_value(){
    if($("#dropdwn").val()=="0"){
        //load nothing
    }else{
        $('#txtval').val($("#dropdown").val());
        $('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
        $('#load_page').load('load_xml.php');
    }
}

For now I put the value of dropdown on the textbox but will also try to get the value of dropdown. The problem is on the second php file that loads on the main page. I can't get the value of $txtval=$_POST['txtval'] when I use this. I will need the value for if else condition.

First you need to sent the parameter to the resource load_xml.php.

function get_value() {
    if ($("#dropdwn").val() == "0") {
        //load nothing
    } else {
        var val = $("#dropdown").val();
        $('#txtval').val(val);
        $('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
        $('#load_page').load('load_xml.php?txtval=' + val);
    }
}

The the load method uses a GET request, not a POST method.

$txtval=$_GET['txtval']

If you want to sent a POST method, then use the syntax

function get_value() {
    if ($("#dropdwn").val() == "0") {
        //load nothing
    } else {
        var val = $("#dropdown").val();
        $('#txtval').val(val);
        $('#load_page').html('<p align="center"><br/><img src="images/popuploader.gif" /><br/><br/></p>');
        $('#load_page').load('load_xml.php?', {
            txtval: val
        });
    }
}

then

$txtval=$_POST['txtval']