<?
$strBeg= file_get_contents($_SERVER['DOCUMENT_ROOT']."/begin.php");
	$strEnd= file_get_contents($_SERVER['DOCUMENT_ROOT']."/end.php");
?>

<script language="JavaScript">
var beg= '<?=$strBeg?>';
var end= '<?=$strEnd?>';
function showIm(im)
{
alert('');
document.write(beg);
document.write(im);
document.write(end);
}	
</script>

Why can't I write the document at runtime with javascript? showIm is called on a mouseclick event.

This does not work either:

<script language="JavaScript">
alert('');
var beg= '<?=file_get_contents($SERVER['DOCUMENT_ROOT']."/begin.php");?>';
var end= '<?=file_get_contents($
SERVER['DOCUMENT_ROOT']."/end.php");?>';
function showIm(im)
{
document.write(beg);
document.write(im);
document.write(end);
}
</script>

I don't even see the alert box when the page opens, it says there are errros on the page.

    I do need a username and password to write access my site via ftp. Do you think I have to log in first from code?

      No that's not it. The data from the file is there. It shows up when I echo the return from file_get_contents. There must be something else wrong.

        What do you see if you look at the generated Javascript? What are the error messages do you get in Firefox's Javscript console?

          I don't have any debugging programs but I think it has something to do with the page I'm trying to write because it write variables just fine.

          It has links and images in html and is the beginning and end of an html document. Should html tags be a problem for javascript?

            Originally posted by aewarnick
            I don't have any debugging programs but I think it has something to do with the page I'm trying to write because it write variables just fine.

            Firefox has a Javascript console built in, that will tell you which line the error is on, what the error was, and point out the spot where the error occurred to you. And unlike Internet Explorer's vague waffle, it's accurate. IE's error messages are so bad it's best to ignore them and view the source yourself, hoping you see something.

            But then again, you do test your websites on different browsers, don't you?

            It has links and images in html and is the beginning and end of an html document. Should html tags be a problem for javascript?

            No, but quotes might.

              When would quotes be a problem? I have alot of double quotes in the php file and maybe some single.

                I just downloaded firefox and have found that many of my images don't show and many of my links don't work. It puts:
                %5C
                in between things and messes up the links. What is going on.

                I did try to see errors but there are none produced.

                  Go to this page and see the output in the console:
                  CLICK
                  I have viewed it and can't figure out what is wrong. Also, please answer the above 2 questions.

                    The error when you click on a thumbnail is produced as a result of this code:

                    This is at the top:
                    
                    <?
                    $begS= file_get_contents($_SERVER['DOCUMENT_ROOT']."/begin.php");
                    $endS= file_get_contents($_SERVER['DOCUMENT_ROOT']."/end.php");
                    ?>
                    <script language="JavaScript">
                    var beg= '<?=$begS;?>';
                    var end= '<?=$endS;?>';
                    function showIm(im)
                    {
                    document.write(beg);
                    document.write(im);
                    document.write(end);
                    }	
                    </script>
                    
                    This is down below in php tags:
                    
                    <a href="#" onclick="showIm('<?=$images[$k][0]?>'); return false;">
                    
                    Error:
                    showIm undefined.

                    How can the function be undefined? It's right there at the top!

                      Firefox's error message reads:

                      Error: unterminated string literal
                      Source File: http://www.foryouandi.com/Space/index.php
                      Line: 41, Column: 9
                      Source Code:
                      var beg= '<html>

                      And it's probably because - as far as Javascript can tell - the line never finishes. IIt follows C's convention that if you want a string to continue over more than one line, you have to use \ on the end of each line except the last to indicate that it continues on to the next line.

                      So in other words the the generated script, instead of reading:

                      <script language="JavaScript">
                      var beg= '<html>
                      <head>
                      <title>ForYouAndI.com</title>
                      .......
                      </body>
                      
                      </html>';
                      

                      Should read

                      <script language="JavaScript">
                      var beg= '<html>\
                      <head>\
                      <title>ForYouAndI.com</title>\
                      .......\
                      </body>\
                      \
                      </html>';
                      

                      But it's a funny way of working: why not just link to another page?

                        I have to dynamically put begin at the top, an image in the middle and end at the bottom. All that on the same page when a user click on a thumbnail. Is there another way to do that?

                          But you're rewriting the entire page! Why not just make the thumbnail a link?

                            Write a Reply...