Answers for "php input onchange"

PHP
0

php input onchange

/*
You can't execute PHP in the browser.
Do an AJAX call or POST to a PHP function on the web server, 
or write a Javascript function that executes in the browser.
*/

// html
<input name="file" onchange="mainInfo(this.value);"
// AJAX
function mainInfo(id) {
    $.ajax({
        type: "GET",
        url: "mypage.php",
        data: "mainid =" + id,
        success: function(result) {
            $("#somewhere").html(result);
        }
    });
};

// php
<?php
    if(isset($_GET['mainid'])){
        mainInfo($_GET['mainid']);
    }
?>
Posted by: Guest on May-01-2021

Browse Popular Code Answers by Language