Page 1 of 1
How to Insert A Java Script
Posted: Fri Sep 12, 2008 5:02 am
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: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:showbox('Div1');">Show box 1 again</a></td>';
print '<td>"eeeee"</td>';
print '</tr>';
print '</table>';
?>
Re: How to Insert A Java Script
Posted: Fri Sep 12, 2008 6:55 am
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...
Re: How to Insert A Java Script
Posted: Fri Sep 12, 2008 7:28 am
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: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...
Re: How to Insert A Java Script
Posted: Fri Sep 12, 2008 7:37 am
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: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:showbox('Div1'); return false;">Show box 1 again</a></td>
<td>eeeee</td>
</tr>
</table>
<?php
// Back to PHP
?>
Re: How to Insert A Java Script
Posted: Fri Sep 12, 2008 7:41 am
by BETA
lol true i do i that way too...

just thought he couldn't use that for some reason... like when u need to insert content dynamically

Re: How to Insert A Java Script
Posted: Fri Sep 12, 2008 7:48 am
by marcth
BETA wrote:lol true i do i that way too...

just thought he couldn't use that for some reason... like when u need to insert content dynamically

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: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.