rhillman Posted August 3, 2007 Share Posted August 3, 2007 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? :-) Link to comment https://forums.phpfreaks.com/topic/63161-solved-using-php-variable-in-php-echod-javascript-within-include-file/ Share on other sites More sharing options...
yarnold Posted August 3, 2007 Share Posted August 3, 2007 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);'; } Link to comment https://forums.phpfreaks.com/topic/63161-solved-using-php-variable-in-php-echod-javascript-within-include-file/#findComment-314827 Share on other sites More sharing options...
rhillman Posted August 3, 2007 Author Share Posted August 3, 2007 There's more code after that, in which the ' is closed, so that's not the problem. Thanks though! :-) Link to comment https://forums.phpfreaks.com/topic/63161-solved-using-php-variable-in-php-echod-javascript-within-include-file/#findComment-315032 Share on other sites More sharing options...
rhillman Posted August 3, 2007 Author Share Posted August 3, 2007 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! Link to comment https://forums.phpfreaks.com/topic/63161-solved-using-php-variable-in-php-echod-javascript-within-include-file/#findComment-315056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.