Forum Moderators: open

Message Too Old, No Replies

onclick event handler in php scripts

         

pitat450

2:48 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



I am new to php scripting, i was trying to rewrite my page into php, but i want to keep my javascript effects. But if i put the string in echo tag it just dont work!

example:
<?echo "
<td align=center bgcolor=\"#5647A1\" onClick=\"window.location.href=\'realizace.html\';\"> click here </td> ;"?>

... and it is so even if i put the back slash in front of " string...
CAN ANYONE HELP?

thanx pitat450

encyclo

3:28 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], pitat450.

Looking briefly at the code, I see two problems: the first is that if you are enclosing your echo with double quotes, you don't need to escape the single quotes around the onclick parapeters. An alternative is to use single quotes for the echo and escape only the single quotes. The second problem is your semi-colon at the end which is placed incorrectly:

Try this (completely untested, mind you):

<?php echo "
<td align=\"center\" bgcolor=\"#5647A1\" onClick=\"window.location.href='realizace.html';\"> click here </td>";?>

or alternatively:

<?php echo '
<td align="center" bgcolor="#5647A1" onClick="window.location.href=\'realizace.html\';"> click here </td>';?>

pitat450

5:17 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



that is it - both ways worked perfektly!
THANK YOU very much encyclo!
U r guys just great ;)