Jump to content

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


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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.