What are the best practices for passing ID and FrameID parameters to a JavaScript function in PHP?

When passing ID and FrameID parameters to a JavaScript function in PHP, it is important to properly escape the values to prevent any potential security vulnerabilities such as cross-site scripting attacks. One way to achieve this is by using htmlspecialchars() function to encode the values before passing them to the JavaScript function.

<?php
$id = htmlspecialchars($_GET['id']);
$frameId = htmlspecialchars($_GET['frameId']);
echo "<script>";
echo "myFunction('$id', '$frameId');";
echo "</script>";
?>