Home:ALL Converter>call javascript function inside a method

call javascript function inside a method

Ask Time:2019-10-20T12:05:17         Author:mehid

Json Formatter

how can i call this js function that is inside the method in an onclick on the button that is inside another method

<?php

class Test
{
    public function GetTest()
    {

       print $HTML = '<button onclick="$this->JavaScript( TestJS() )">OK</button>';                

    }

    public function JavaScript( $JS )
    {
        echo '
            <script>
                function TestJS() {
                    alert ("OK!");
                }
            </script>
        ';
    }
}

Author:mehid,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58469944/call-javascript-function-inside-a-method
yy