0

I am trying to implement a little code in HTML; calling a PHP onclick in HTML using the solution here and it just runs to a blank page. Upon inspection, I noticed a typo in my code but after i corrected it the output is still the same i.e. it opens a blank page with no echo or anything.

My question: Is there a way to debug my code so my browser (i suspect) can notify me as to what part or line of my code the error is coming from, like in Java IDEs?

<?php
function working(){
    echo 'WORKED ';
}    
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dice Game</title>
</head>
<body>
<div>
<div>
    <h1 id="player1" onclick="document.write('<?php working(); ?>')">
        ENTER PLAYER 1 NAME
    </h1>
</div>
</div>
</body>
</html>

Note: I use Chrome

kbluue
  • 369
  • 1
  • 5
  • 20
  • Open the element inspector, there will be a section called *"console"*. There errors will show up. May I add that this approach of PHP and Javascript melting is not really ideal and good practice.. – Nytrix Jul 09 '17 at 01:58
  • 1
    Once page opens in the browser press f12. There by investigating the code step by step Please visit https://developers.google.com/web/tools/chrome-devtools/javascript/reference – Lova Chittumuri Jul 09 '17 at 02:01
  • I think i found the error: it seems the browser recognizes this line '

    ' as a comment. Any idea how i can fix that?

    – kbluue Jul 09 '17 at 02:41
  • you can use eclips if you want. – always-a-learner Jul 09 '17 at 04:17

3 Answers3

1

Browsers like Firefox, Chrome, etc. have Developer Tools. Hit F12 to activate it and then look at Console, then reload the page. That should tell you what your errors are.

Difster
  • 3,264
  • 2
  • 22
  • 32
1

You are "implementing a little code in HTML; calling a PHP onclick in HTML"

Firstly if your are using a php code in html, So extension of file should .php and there should be a server(ex. wamp,xamp,lamp) to run it. if it having extension .html then it will not show any error, because html files is compiled at browser lever and php is server side language. So if make right extension of your file means make ext .php then run you file, then if there will be any error then you will got message on browser also hinting line number of error.

0

On Chrome or Firefox use F12 to Debug (Window) or simply right click any in page select Inspect Elements then choose Console tabs

Sterli
  • 49
  • 1
  • 8