Jannice Jannice - 2 months ago 19
HTML Question

Return confirm window in JavaScript

I'm working with an

if else
statement which will only display depending on the statement. My confirm window is not working. It will just go to the log-out page without the confirmation.

My code:

else
{
echo "
<td class='td1' align='center'>
<a href='logout.php' onclick='return confirm('Are you sure you want to Log Out?')'><img src='./buttons/logout1.png' width='50' height='35' alt='Log Out'></a>
</td>
</tr>
</table>

";}

Answer

<table><tr>
<td class='td1' align='center'>
<a href='logout.php' onclick="return confirm('Are you sure you want to Log Out?')">Log Out</a>
</td>
</tr>
</table>

Change your code to this

else
{
echo "
<td class='td1' align='center'>
<a href='logout.php' onclick=\"return confirm('Are you sure you want to Log Out?')\"><img src='./buttons/logout1.png' width='50' height='35' alt='Log Out'></a>
</td>
</tr>
</table>

";}
  1. Use escape sequence inside onlclick.
Comments