Please show us the PHP code, I can't help you if I don't know specifically what you're trying to echo.
__________________ Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
surreal, best thing you could do to avoid PHP echo issues with this chunk of Javascript would be to stop PHP parsing when it gets to this script. Something like this:
PHP Code:
<?php
$javascript = 1;
if ($javascript == 1) {
?>
function rollOn(obj){
obj.src=obj.src.replace(/.png/,'blue.png');
}
function rollOff(obj){
obj.src=obj.src.replace(/blue.png/,'.png');
}
surreal, best thing you could do to avoid PHP echo issues with this chunk of Javascript would be to stop PHP parsing when it gets to this script. Something like this:
PHP Code:
<?php $javascript = 1;
if ($javascript == 1) { ?>
function rollOn(obj){ obj.src=obj.src.replace(/.png/,'blue.png'); } function rollOff(obj){ obj.src=obj.src.replace(/blue.png/,'.png'); }
<?php } ?>
If you're using a template system, though, that may get a bit hairy.
__________________ Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
My posts, comments, code, and suggestions reflect only my personal views.
Web Portfolio and Code Snippets: http://shanechism.com
well I tried the parenthesis, it didnt seem to help
I am still getting an error on the same string but now its not giving me any specifics.
Here is the code I am trying to work in its entirty
Code:
<?php
echo'
<script language="javascript" type="text/javascript">
function rollOn(obj){
obj.src=obj.src.replace(/.png/,'blue.png');
}
function rollOff(obj){
obj.src=obj.src.replace(/blue.png/,'.png');
}
var currentSpan = 1;
function showMe(n) {
document.getElementById("ex_"+currentSpan).style.display = "none";
document.getElementById("ex_"+n).style.display = "block";
currentSpan = n;
}
var currentDiv = 1;
function showcontent(n) {
// Hide the current side content that is being shown
document.getElementById("SC_"+currentDiv).style.display = "none";
// Show the new side content
document.getElementById("SC_"+n).style.display = "block";
// Set the current open side content
currentDiv = n;
}
function bkgrnd() {
var bg = [];
var n=0;
var base = "http:\/\/i95.photobucket.com/albums/l136/surreal5335/RE%20site/house"
bg[n] = base + "6.png";
bg[n++] = base + "1.png";
bg[n++] = base + "3.png";
bg[n++] = base + "4.png";
bg[n++] = base + "5.png";
var rnd = Math.floor(Math.random() * bg.length) ;
return '<BODY BACKGROUND="' +bg[rnd]+ '"' +' BGCOLOR="#FFFFFF">'
}
</script>';
?>
I am going to be using this code as a seperate file and including it into another php document which is echoing html. I am using php bc of its ability to include external files.
There is no PHP used within that function, so you can completely remove the php indicators and the echo. If you really want to use it, look into heredoc syntax; it should reduce the complication on you're escapes. I'd just remove the <?php from it.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Ok I have diagnosed the problem, it lies with with single quote conflicts seeing as the echo is done with single quotes. I made a change to that line and made it all double quotes and that fixed that... there is just one last line I am not sure how to change, it has single and double quotes in it.
What you're JS sees is \' + ..., you need to escape you're escapes to make this work with inline echos.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Yeah, use the style object. Since you've just got the tag, you can write it in instead:
Code:
return \'<body style="background: #fff url(\\\' + bg[rnd] + \\\') no-repeat fixed center center">\'
This uses CSS which is far more flexible than embedded tag attributes. The above is a shortened background tag which combines background-color, background-image, background-repeat, background-attachment, background-position-x and background-position-y.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php