Page 1 of 1
OnClick help
Posted: Tue Mar 09, 2010 4:32 am
by Jay87
I want to add an onclick command to the following code:
Code: Select all
<td class=smooth" . $stripe .">" . substr($item['description'],0,65) . "</td><td class=smooth" . $stripe .">" . $item['logged_fmt'] . "</td><td class=smooth" . $stripe .">" . $days . "d " . $hours . "h " . $mins . "m </td>
everytime i copy and paste:
Code: Select all
onclick=\"document.location='viewcall.php?id=
into the <td but it just breaks the page....
Any ideas?
Re: OnClick help
Posted: Tue Mar 09, 2010 7:37 am
by cpetercarter
Surely your code for 'onclick' is not complete. It should be something like:
Code: Select all
onclick=\"document.location='viewcall.php?id=[some-id]'\"
.
But why are you using Javascript here? Cant you simply place a normal link
Code: Select all
<a href="viewcall.php?id=[some-id]">Your item description</a>
between <td> and </td>?
Re: OnClick help
Posted: Tue Mar 09, 2010 9:31 am
by Jay87
cpetercarter wrote:Surely your code for 'onclick' is not complete. It should be something like:
Code: Select all
onclick=\"document.location='viewcall.php?id=[some-id]'\"
.
Your right it's: onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix'];
But why are you using Javascript here? Cant you simply place a normal link
Code: Select all
<a href="viewcall.php?id=[some-id]">Your item description</a>
between <td> and </td>?
Because each row has a unique description i.e. call 0001 description could be: 'not receiving emails' and then call 0002 description could be 'can we set up a new user'
I tried:
Code: Select all
<td class=smooth onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix']; . $stripe .">" . substr($item['description'],0,75) . "</td>
but this doesn't work.
Re: OnClick help
Posted: Tue Mar 09, 2010 9:35 am
by Jay87
Code: Select all
<td class=smooth onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix']; $stripe .">" . substr($item['description'],0,75) . "</td>
the onclick works but has totally screwed up the formatting of the table, syntax error?
Re: OnClick help
Posted: Tue Mar 09, 2010 9:46 am
by Jay87
This applies the onclick to the whole row:
Code: Select all
<tr style=\"color:green;\" onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix']; if($HTTP_SERVER_VARS['QUERY_STRING']){ echo "&";} echo $HTTP_SERVER_VARS['QUERY_STRING'] . "';\">
I want it just to apply on the:
Code: Select all
<td class=smooth" . $stripe .">" . substr($item['description'],0,75) . "</td>
but can't work out how to add the onclick bit to the above code!

Re: OnClick help
Posted: Tue Mar 09, 2010 11:41 am
by cpetercarter
You need to sit down and carefully work through the correct syntax for the 'onclick' bit. The 'onclick' code needs to be surrounded by (escaped) double quotation marks, and the bit following 'window.location=' needs to be in single quotation marks. So the correct code should I think be:
Code: Select all
echo "<td onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix'] . "'\">" . substr($item['description'],0,75) . "</td>";
If you are still stuck, have a look at the source code for your web page in your browser. This shows the html that your code is outputting. It is often obvious from that where you have gone wrong, where you have omitted a set of quotation marks etc.
I still do not understand your problem with using a normal html link. Why will this not do what you want?
Code: Select all
echo "<td><a href=\"viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix'] . "\">" . substr($item['description'],0,75) . "</a></td>";