I have a PHP file which have variables collected from HTML. I have also a JavaScript function.

I want to call the JavaScript function via PHP but I know it's impossible because the PHP code is before the JavaScript code.

I put it before the JS code because JavaScript collects variables from the PHP code only when the PHP is before the JavaScript file.

How can I call the JS function from PHP and still have the variables? (By echo 'after();'

This is my index.php:

```
<?php
if(isset($_REQUEST['name']) && isset($_REQUEST['secondName']))
{
    $name = $_REQUEST['name'];
    $secondName = $_REQUEST['secondName'];
    echo '<script>after();</script>';
}
else
{
    $name = '';
    $secondName = '';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    function after()
    {
    var name = '<?=$name?>';
    var secondName = '<?=$secondName?>';
    var str = "         ";
    if(!str.replace(/\s/g, '').length)
    {
        alert("error");
    }
    else
    {
        $("#pre-text").fadeIn();
        $("#text").html(fullName);
        $("#pre-text").click(function(){
        $(this).fadeOut();
        });
    }   
    }
});
</script>
</head>
<body>
<form method="get">
<p>First name: <input type="text" name="name"></p>
<p>Second name: <input type="text" name="secondName"> <input type="submit"></p>
<p id="pre-text" style="display:none">Your first name is: <span id="text"></span>. You can also click me to hide.</p>
</form>

</body>
</html>

```

Thanks for help.

EDIT: I want to call the function after().