0

Hey it looks like this code is not working because its interfering with the php. Here is the code:

<div onclick='javascript:alert('new')'>New</div>

How can I write that code in PHP it seems to be messing up my php?

2 Answers2

5

The reason that it is messing things up is that the quotes around the new is messing up the quotes around the entire javascript.

To fix this you can try this:

<div onclick='javascript:alert("new")'>New</div>

Or you can do this:

<div onclick="javascript:alert('new')">New</div>
Razor Storm
  • 12,167
  • 20
  • 88
  • 148
4

You can't, PHP is a server side language and can't respond to on page clicks that way. It's screwing up your PHP because you've screwed up the quotes

<div onclick='javascript:alert("new")'>New</div>
Rick Calder
  • 18,310
  • 3
  • 24
  • 41