Jump to content

[SOLVED] Using PHP variable in PHP-Echo'd Javascript within Include file


rhillman

Recommended Posts

Alright, so here's something fun.  I'm having to modify a script, which is set up as follows:

 

PHP file, including another PHP file, which is echo'ing all sorts of Javascript.

 

I need to pull a variable from the main PHP file, to insert into a Javascript string within the included PHP file.  Here's the code:

echo '<script type="text/javascript">
function changeContent(pos) {';
if (!$autodetect_noscoll) {
	echo '
centerpos = thumbstwg_offset[parseInt(pos)];
';
} else {
	echo '
if (thumbstwg_offset.length > ' . (($numberofpics * 2) + 1) . ') {
      centerpos = thumbstwg_offset[parseInt(pos)];
}
';
}
echo '
reload=0;
changeContentWait(pos);
}

 

Here's what I've been trying:

echo '<script type="text/javascript">
function changeContent(pos) {';
if (!$autodetect_noscoll) {
	echo '
centerpos = thumbstwg_offset[parseInt(pos)];
';
} else {
	echo '
if (thumbstwg_offset.length > ' . (($numberofpics * 2) + 1) . ') {
  centerpos = thumbstwg_offset[parseInt(pos)];
}
';
}
echo '
        document.sohaform.item_name.value = ' . $image . ';
reload=0;
changeContentWait(pos);
}

 

What shows up in the source code is everything up to the 'equals' sign.  The $image variable doesn't parse like it does in other included PHP files.  Help?  :-)

You haven't closed your ' tag have you?

 

echo '<script type="text/javascript">
function changeContent(pos) {';
if (!$autodetect_noscoll) {
	echo '
centerpos = thumbstwg_offset[parseInt(pos)];
';
} else {
	echo '
if (thumbstwg_offset.length > ' . (($numberofpics * 2) + 1) . ') {
  centerpos = thumbstwg_offset[parseInt(pos)];
}
';
}
echo '
        document.sohaform.item_name.value = ' . $image . ';
reload=0;
changeContentWait(pos);';
}

Problem solved by a friend of mine.  That line of code should read as follows:

 

document.sohaform.item_name.value = "' . $image . '";

 

Now I've got a whole new set of problems, but I think it goes beyond the scope of this forum.

 

Thanks for the efforts put forth, I really appreciate it!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.