how to use php variable in java script alert code example Example: alert a php variable echo '<script type="text/javascript">alert("'.$error.'");</script>';