How to Insert A Java Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rangana
Forum Newbie
Posts: 6
Joined: Thu Sep 04, 2008 4:36 am

How to Insert A Java Script

Post by Rangana »

I want to add that code in within php code. but that is not work but without php code that is work how am i implement that PLS help me

That code is work

Code: Select all

<table border="2">
<tr>
<td> <p align="left"><a href="javascript&#058;showbox('Div1');">Show box 1 again</a></td>
<td>"eeeee"</td>
</tr>
</table>
I wnt to do in this way but it's not work

Code: Select all

<?php
print '<table border="2">';
print '<tr>';
print '<td> <p align="left"><a href="javascript&#058;showbox('Div1');">Show box 1 again</a></td>';
print '<td>"eeeee"</td>';
print '</tr>';
print '</table>';
?>
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: How to Insert A Java Script

Post by jayshields »

If you're going to use single quotes inside single quotes (or double quotes inside double quotes) then you need to escape the inner quotes with a backslash. For some reason the PHP tag parser on here won't let me give you an example...
BETA
Forum Commoner
Posts: 47
Joined: Fri Jul 25, 2008 3:21 am

Re: How to Insert A Java Script

Post by BETA »

I use to do it this way

Code: Select all

<?php 
echo '
<table border="2">
<tr>
<td> <p align="left"><a href="javascript&#058;showbox('Div1');">Show box 1 again</a></td>
<td>"eeeee"</td>
</tr>
</table>';
?>
 
dunno really if thats the good way but it works for me...
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

Re: How to Insert A Java Script

Post by marcth »

BETA wrote:I use to do it this way

Code: Select all

<?php 
echo '
<table border="2">
<tr>
<td> <p align="left"><a href="javascript&#058;showbox('Div1');">Show box 1 again</a></td>
<td>"eeeee"</td>
</tr>
</table>';
?>
 
dunno really if thats the good way but it works for me...
You don't need PHP here, so why use it?

Code: Select all

<?php
// Some PHP code
?>
<table>
  <tr>
    <td><a href="javascript&#058;showbox('Div1'); return false;">Show box 1 again</a></td>
    <td>eeeee</td>
  </tr>
</table>
<?php
 // Back to PHP
?>
 
BETA
Forum Commoner
Posts: 47
Joined: Fri Jul 25, 2008 3:21 am

Re: How to Insert A Java Script

Post by BETA »

lol true i do i that way too... :lol: just thought he couldn't use that for some reason... like when u need to insert content dynamically :P
marcth
Forum Contributor
Posts: 142
Joined: Mon Aug 25, 2008 8:16 am

Re: How to Insert A Java Script

Post by marcth »

BETA wrote:lol true i do i that way too... :lol: just thought he couldn't use that for some reason... like when u need to insert content dynamically :P
It is extremely important to separate your PHP from your presentation--I don't even put them in the same file.

Code: Select all

 
<?php
  $boxes = array(
    1 => 'Box 1',
    2 => 'Box 2',
    3 => 'Box 3',
  );
?>
 

Code: Select all

 
<table>
  <?php foreach($boxes as $id=>$value) { ?>
  <tr>
    <td><a href="javascript&#058;showbox('Div<?= $id ?>'); return false;">Show <?= $value ?> again</a></td>
    <td>eeeee</td>
  </tr>
  </php } ?>
</table>
Edit: Some people feel strongly that using <?= ?> instead of <?php echo '' ?> is bad.
Post Reply