php call javascript function with parameters code example

Example 1: javascript call php function with parameters

var deleteClient = function(id) {
    $.ajax({
        url: 'path/to/php/file',
        type: 'POST',
        data: {id:id},
        success: function(data) {
            console.log(data); // Inspect this in your console
        }
    });
};

Example 2: php echo call javascript function with parameters

// Most effective way to call a javascript function with parameter of PHP variable
echo '<input type="button" value="Button" onclick="return openEditor(\'' . $path_image . '\')">';