nesting JS in echo's

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Request-1

    nesting JS in echo's

    hi folks,

    html coder here, new and terrified * of php!!
    aaaaaa!

    i'm trying to bury a JS script to rotate a photo, in a page i converted from
    html to php.
    the conversion went well, it was to use a php session cookie to stop the
    repeating of an embedded video file on a per session basis;
    i amended the php code to display a still pic if the session cookie value
    was nil.

    worked fine.

    thought I'd try integrating a tested and true JS image random rotator script
    into the echo command, but the problem was the syntax of the single quotes
    and double quotes needed in the doc.write and variable sequences in the JS.

    i tried escaping the double quotes (my echo used double quotes), but to no
    avail.

    here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
    variable holding the randomly assigned number that chooses the picture.

    any help much appreciated..


    +++++++++++++++ +

    { echo "

    <script language='JavaS cript1.2'>
    <!-- begin
    document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
    // end -->
    </script>
    "; }

    +++++++++++++++ +++++++++++

    thanks


  • jimp@specsol.spam.sux.com

    #2
    Re: nesting JS in echo's

    Request-1 <hello@you.comw rote:
    hi folks,
    >
    html coder here, new and terrified * of php!!
    aaaaaa!
    >
    i'm trying to bury a JS script to rotate a photo, in a page i converted from
    html to php.
    the conversion went well, it was to use a php session cookie to stop the
    repeating of an embedded video file on a per session basis;
    i amended the php code to display a still pic if the session cookie value
    was nil.
    >
    worked fine.
    >
    thought I'd try integrating a tested and true JS image random rotator script
    into the echo command, but the problem was the syntax of the single quotes
    and double quotes needed in the doc.write and variable sequences in the JS.
    >
    i tried escaping the double quotes (my echo used double quotes), but to no
    avail.
    >
    here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
    variable holding the randomly assigned number that chooses the picture.
    >
    any help much appreciated..
    >
    >
    +++++++++++++++ +
    >
    { echo "
    >
    <script language='JavaS cript1.2'>
    <!-- begin
    document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
    // end -->
    </script>
    "; }
    >
    +++++++++++++++ +++++++++++
    >
    thanks
    It will work, but it is probably easier to do a line at a time, as in
    these example lines from a PHP page that does JS:

    echo "<script LANGUAGE='JavaS cript'>\n";

    echo "<INPUT type=\"hidden\" name=\"clock\" size=\"3\" value=\"\">\n";


    --
    Jim Pennino

    Remove .spam.sux to reply.

    Comment

    • 703designs

      #3
      Re: nesting JS in echo's

      On Nov 7, 6:58 pm, "Request-1" <he...@you.comw rote:
      hi folks,
      >
      html coder here, new and terrified * of php!!
      aaaaaa!
      >
      i'm trying to bury a JS script to rotate a photo, in a page i converted from
      html to php.
      the conversion went well, it was to use a php session cookie to stop the
      repeating of an embedded video file on a per session basis;
      i amended the php code to display a still pic if the session cookie value
      was nil.
      >
      worked fine.
      >
      thought I'd try integrating a tested and true JS image random rotator script
      into the echo command, but the problem was the syntax of the single quotes
      and double quotes needed in the doc.write and variable sequences in the JS.
      >
      i tried escaping the double quotes (my echo used double quotes), but to no
      avail.
      >
      here's the JS CODE i use in the tail end of my PHP.  "picnumber" is the
      variable holding the randomly assigned number that chooses the picture.
      >
      any help much appreciated..
      >
      +++++++++++++++ +
      >
      { echo "
      >
         <script language='JavaS cript1.2'>
              <!-- begin
          document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
         // end  -->
      </script>
         "; }
      >
      +++++++++++++++ +++++++++++
      >
      thanks
      You can do this:

      { ?>

      <!-- No escaping required -->

      <script type='text/javascript'>
      document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
      </script>

      <?php }

      Is "picnumber" a JavaScript or PHP veriable?

      Thomas

      Comment

      • 703designs

        #4
        Re: nesting JS in echo's

        On Nov 7, 7:16 pm, 703designs <thomasmal...@g mail.comwrote:
        On Nov 7, 6:58 pm, "Request-1" <he...@you.comw rote:
        >
        >
        >
        hi folks,
        >
        html coder here, new and terrified * of php!!
        aaaaaa!
        >
        i'm trying to bury a JS script to rotate a photo, in a page i convertedfrom
        html to php.
        the conversion went well, it was to use a php session cookie to stop the
        repeating of an embedded video file on a per session basis;
        i amended the php code to display a still pic if the session cookie value
        was nil.
        >
        worked fine.
        >
        thought I'd try integrating a tested and true JS image random rotator script
        into the echo command, but the problem was the syntax of the single quotes
        and double quotes needed in the doc.write and variable sequences in theJS.
        >
        i tried escaping the double quotes (my echo used double quotes), but tono
        avail.
        >
        here's the JS CODE i use in the tail end of my PHP.  "picnumber" is the
        variable holding the randomly assigned number that chooses the picture.
        >
        any help much appreciated..
        >
        +++++++++++++++ +
        >
        { echo "
        >
           <script language='JavaS cript1.2'>
                <!-- begin
            document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
           // end  -->
        </script>
           "; }
        >
        +++++++++++++++ +++++++++++
        >
        thanks
        >
        You can do this:
        >
        { ?>
        >
        <!-- No escaping required -->
        >
        <script type='text/javascript'>
            document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
        </script>
        >
        <?php }
        >
        Is "picnumber" a JavaScript or PHP veriable?
        >
        Thomas
        You can also use "heredoc":


        <?php
        echo <<<DOESNTMATTER WHATTHISSAYS

        <!-- No escaping required -->
        <script type='text/javascript'>
        document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
        </script>


        DOESNTMATTERWHA TTHISSAYS;
        // Don't indent the above line line

        Thomas

        Comment

        • 703designs

          #5
          Re: nesting JS in echo's

          On Nov 7, 7:24 pm, 703designs <thomasmal...@g mail.comwrote:
          On Nov 7, 7:16 pm, 703designs <thomasmal...@g mail.comwrote:
          >
          >
          >
          On Nov 7, 6:58 pm, "Request-1" <he...@you.comw rote:
          >
          hi folks,
          >
          html coder here, new and terrified * of php!!
          aaaaaa!
          >
          i'm trying to bury a JS script to rotate a photo, in a page i converted from
          html to php.
          the conversion went well, it was to use a php session cookie to stop the
          repeating of an embedded video file on a per session basis;
          i amended the php code to display a still pic if the session cookie value
          was nil.
          >
          worked fine.
          >
          thought I'd try integrating a tested and true JS image random rotatorscript
          into the echo command, but the problem was the syntax of the single quotes
          and double quotes needed in the doc.write and variable sequences in the JS.
          >
          i tried escaping the double quotes (my echo used double quotes), but to no
          avail.
          >
          here's the JS CODE i use in the tail end of my PHP.  "picnumber" isthe
          variable holding the randomly assigned number that chooses the picture.
          >
          any help much appreciated..
          >
          +++++++++++++++ +
          >
          { echo "
          >
             <script language='JavaS cript1.2'>
                  <!-- begin
              document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
             // end  -->
          </script>
             "; }
          >
          +++++++++++++++ +++++++++++
          >
          thanks
          >
          You can do this:
          >
          { ?>
          >
          <!-- No escaping required -->
          >
          <script type='text/javascript'>
              document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
          </script>
          >
          <?php }
          >
          Is "picnumber" a JavaScript or PHP veriable?
          >
          Thomas
          >
          You can also use "heredoc":http://us3.php.net/manual/en/languag...language.types...
          >
          <?php
          echo <<<DOESNTMATTER WHATTHISSAYS
          >
          <!-- No escaping required -->
          <script type='text/javascript'>
              document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
          </script>
          >
          DOESNTMATTERWHA TTHISSAYS;
          // Don't indent the above line line
          >
          Thomas
          My bad, should have clarified: "DOESNTMATTERWH ATTHISSAYS" means just
          that, but those two have to match precisely.

          Thomas

          Comment

          • Request-1

            #6
            Re: nesting JS in echo's

            "703designs " <thomasmallen@g mail.comwrote in message
            news:3501dda4-b5a3-4581-9940-e036eb3146e6@r3 7g2000prr.googl egroups.com...
            On Nov 7, 7:24 pm, 703designs <thomasmal...@g mail.comwrote:
            On Nov 7, 7:16 pm, 703designs <thomasmal...@g mail.comwrote:
            >
            >
            >
            On Nov 7, 6:58 pm, "Request-1" <he...@you.comw rote:
            >
            hi folks,
            >
            html coder here, new and terrified * of php!!
            aaaaaa!
            >
            i'm trying to bury a JS script to rotate a photo, in a page i
            converted from
            html to php.
            the conversion went well, it was to use a php session cookie to stop
            the
            repeating of an embedded video file on a per session basis;
            i amended the php code to display a still pic if the session cookie
            value
            was nil.
            >
            worked fine.
            >
            thought I'd try integrating a tested and true JS image random rotator
            script
            into the echo command, but the problem was the syntax of the single
            quotes
            and double quotes needed in the doc.write and variable sequences in
            the JS.
            >
            i tried escaping the double quotes (my echo used double quotes), but
            to no
            avail.
            >
            here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
            variable holding the randomly assigned number that chooses the
            picture.
            >
            any help much appreciated..
            >
            +++++++++++++++ +
            >
            { echo "
            >
            <script language='JavaS cript1.2'>
            <!-- begin
            document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
            // end -->
            </script>
            "; }
            >
            +++++++++++++++ +++++++++++
            >
            thanks
            >
            You can do this:
            >
            { ?>
            >
            <!-- No escaping required -->
            >
            <script type='text/javascript'>
            document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
            </script>
            >
            <?php }
            >
            Is "picnumber" a JavaScript or PHP veriable?
            >
            Thomas
            >
            You can also use
            "heredoc":http://us3.php.net/manual/en/languag...language.types...
            >
            <?php
            echo <<<DOESNTMATTER WHATTHISSAYS
            >
            <!-- No escaping required -->
            <script type='text/javascript'>
            document.write( "<img src='images/swap/' + picnumber + '.jpg'>");
            </script>
            >
            DOESNTMATTERWHA TTHISSAYS;
            // Don't indent the above line line
            >
            Thomas
            My bad, should have clarified: "DOESNTMATTERWH ATTHISSAYS" means just
            that, but those two have to match precisely.

            Thomas







            thanks guys but no luck.
            i'm swimming in single & double-quote-land.


            I'll list the segments of PHP code I used below; if anyone can spot the
            problem,
            please bellow..

            thanks ...
            (problem seems in the php echo'ing of the JS)
            (doc is saved with ".php" extension)






            at very top of doc...

            <?php setcookie("firs ttime","no") ?>

            then, the normal doctype, html tags, plus the following scripts to run the
            activex for the video ...

            <script src="Scripts/AC_RunActiveCon tent.js"
            type="text/javascript"></script>
            <script src="Scripts/AC_ActiveX.js"
            type="text/javascript"></script>

            then, I tried to "php-ize" the JS that sets the random variable ... (in
            single lines as suggestd....)

            <?php
            echo '<script language="javas cript">\n';
            echo 'var picswap;\n';
            echo 'picswap=new Image(320, 240);\n';
            echo 'picswap.src="/images/swap/1.jpg"\n';
            echo 'var picno = Math.random()*2 6;\n';
            echo 'picno = Math.round(picn o)\n';
            echo '</script>';
            ?>


            then, end of <headand more <htmlstuff ...
            then, the PHP codes the ECHO's the activx/object embed stuff which plays the
            movie only if you are 1st-time loading the page...


            <?php
            $firsttime = $_COOKIE[firsttime];
            if (@$firsttime != "no") { echo "


            <script type='text/javascript'>
            AC_AX_RunConten t(
            'id','mediaPlay er','width','32 0','height','28 0','classid','C LSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95',' codebase','http ://activex.microso ft.com/activex/controls/mplayer/en/nsmp2inf.cab#Ve rsion=5,1,52,70 1','standby','L oading
            Microsoft Windows Media Player
            components...', 'type','applica tion/x-oleobject','plu ginspage','http ://microsoft.com/windows/mediaplayer/en/download/','name','media Player','displa ysize','4','aut osize','-1','bgcolor','d arkblue','showc ontrols','true' ,'showtracker', '-1','showdisplay ','0','showstat usbar','true',' videoborder3d', '-1','src','movie s/bodymechs.wmv', 'autostart','tr ue','designtime sp','5311','loo p','false','fil ename','movies/bodymechs.wmv', 'animationatsta rt','true','tra nsparentatstart ','true'
            ); //end AC code
            </script><noscrip t><OBJECT id='mediaPlayer ' width='320' height='280'
            classid='CLSID: 22d6f312-b0f6-11d0-94ab-0080c74c7e95'
            codebase='http://activex.microso ft.com/activex/controls/mplayer/en/nsmp2inf.cab#Ve rsion=5,1,52,70 1'
            standby='Loadin g Microsoft Windows Media Player components...'
            type='applicati on/x-oleobject'>
            <param name='fileName' value='movies/movie01.wmv'><p aram
            name='animation atStart' value='true'>
            <param name='transpare ntatStart' value='true'>
            <param name='autoStart ' value='true'>
            <param name='showContr ols' value='true'>
            <param name='loop' value='false'>
            <param name='ShowStatu sBar' value='true'>
            <EMBED type='applicati on/x-mplayer2'
            pluginspage='ht tp://microsoft.com/windows/mediaplayer/en/download/'
            id='mediaPlayer ' name='mediaPlay er' displaysize='4' autosize='-1'
            bgcolor='darkbl ue' showcontrols='t rue' showtracker='-1'
            showdisplay='0' showstatusbar=' 0' videoborder3d='-1' width='320'
            height='240'
            src='movies/movie01.wmv' autostart='fals e' designtimesp='5 311'
            loop='false'>
            </EMBED>
            </OBJECT></noscript>"; }



            then, the IF branch, that sets the condition for followup visits to the
            page....


            if (@$firsttime != "")
            { echo "<script language='JavaS cript1.2'>\n";
            echo "<!-- begin \n";
            echo "document.write (\"'<img src='images/swap/'+
            picno + '.jpg'>\");\n";
            echo "// end -->\n";
            echo "</script>"; }

            ?>









            Comment

            • Jerry Stuckle

              #7
              Re: nesting JS in echo's

              Request-1 wrote:
              hi folks,
              >
              html coder here, new and terrified * of php!!
              aaaaaa!
              >
              i'm trying to bury a JS script to rotate a photo, in a page i converted from
              html to php.
              the conversion went well, it was to use a php session cookie to stop the
              repeating of an embedded video file on a per session basis;
              i amended the php code to display a still pic if the session cookie value
              was nil.
              >
              worked fine.
              >
              thought I'd try integrating a tested and true JS image random rotator script
              into the echo command, but the problem was the syntax of the single quotes
              and double quotes needed in the doc.write and variable sequences in the JS.
              >
              i tried escaping the double quotes (my echo used double quotes), but to no
              avail.
              >
              here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
              variable holding the randomly assigned number that chooses the picture.
              >
              any help much appreciated..
              >
              >
              +++++++++++++++ +
              >
              { echo "
              >
              <script language='JavaS cript1.2'>
              <!-- begin
              document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
              // end -->
              </script>
              "; }
              >
              +++++++++++++++ +++++++++++
              >
              thanks
              >
              >
              You have an extra single quote before <img ...



              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Request-1

                #8
                Re: nesting JS in echo's


                "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                news:gf2t4m$inr $1@registered.m otzarella.org.. .
                Request-1 wrote:
                >hi folks,
                >>
                >html coder here, new and terrified * of php!!
                >aaaaaa!
                >>
                >i'm trying to bury a JS script to rotate a photo, in a page i converted
                >from html to php.
                >the conversion went well, it was to use a php session cookie to stop the
                >repeating of an embedded video file on a per session basis;
                >i amended the php code to display a still pic if the session cookie value
                >was nil.
                >>
                >worked fine.
                >>
                >thought I'd try integrating a tested and true JS image random rotator
                >script into the echo command, but the problem was the syntax of the
                >single quotes and double quotes needed in the doc.write and variable
                >sequences in the JS.
                >>
                >i tried escaping the double quotes (my echo used double quotes), but to
                >no avail.
                >>
                >here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
                >variable holding the randomly assigned number that chooses the picture.
                >>
                >any help much appreciated..
                >>
                >>
                >++++++++++++++ ++
                >>
                >{ echo "
                >>
                > <script language='JavaS cript1.2'>
                > <!-- begin
                > document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
                > // end -->
                ></script>
                > "; }
                >>
                >++++++++++++++ ++++++++++++
                >>
                >thanks
                >
                You have an extra single quote before <img ...


                Hi Jerry,

                the single quote is actually necessary in JS when you're using
                document.write to add strings in series (is it called "concatenat ing" or
                something?). so the <img src...statement was broken down into 3 seperate
                stings to be re-joined - all within the double-quote nested doc.write stmt.
                my mistake was to leave the image path in single quotes; instead I tried
                "escaped double quotes" to complete the image path, like so,

                { echo "<script language='JavaS cript1.2'>\n";
                echo "<!-- begin \n";
                echo "document.write ('<img src=\"images/swap/' + picnumber +'.jpg\"
                width=\"320\" height=\"240\" border=\"0\" alt=\"Fitness Training
                Image\">');\n";
                echo "// end -->\n";
                echo "</script>"; }


                but no avail. still no pic shows up.

                anyway. i get really confused with all the nested stuff and single-double
                quotes. i may try that "heredoc" thing that Thomas suggested. I'll need a
                couple of beers first. Friday night on Javascript? Bad!


                Comment

                • 703designs

                  #9
                  Re: nesting JS in echo's

                  On Nov 7, 9:47 pm, "Request-1" <he...@you.comw rote:
                  "Jerry Stuckle" <jstuck...@attg lobal.netwrote in message
                  >
                  news:gf2t4m$inr $1@registered.m otzarella.org.. .
                  >
                  >
                  >
                  Request-1 wrote:
                  hi folks,
                  >
                  html coder here, new and terrified * of php!!
                  aaaaaa!
                  >
                  i'm trying to bury a JS script to rotate a photo, in a page i converted
                  from html to php.
                  the conversion went well, it was to use a php session cookie to stop the
                  repeating of an embedded video file on a per session basis;
                  i amended the php code to display a still pic if the session cookie value
                  was nil.
                  >
                  worked fine.
                  >
                  thought I'd try integrating a tested and true JS image random rotator
                  script into the echo command, but the problem was the syntax of the
                  single quotes and double quotes needed in the doc.write and variable
                  sequences in the JS.
                  >
                  i tried escaping the double quotes (my echo used double quotes), but to
                  no avail.
                  >
                  here's the JS CODE i use in the tail end of my PHP.  "picnumber" is the
                  variable holding the randomly assigned number that chooses the picture..
                  >
                  any help much appreciated..
                  >
                  +++++++++++++++ +
                  >
                  { echo "
                  >
                     <script language='JavaS cript1.2'>
                          <!-- begin
                      document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
                     // end  -->
                  </script>
                     "; }
                  >
                  +++++++++++++++ +++++++++++
                  >
                  thanks
                  >
                  You have an extra single quote before <img ...
                  >
                  Hi Jerry,
                  >
                  the single quote is actually necessary in JS when you're using
                  document.write to add strings in series (is it called "concatenat ing" or
                  something?).  so the <img src...statement was broken down into 3 seperate
                  stings to be re-joined - all within the double-quote nested doc.write stmt.
                  my mistake was to leave the image path in single quotes; instead I tried
                  "escaped double quotes" to complete the image path, like so,
                  >
                  { echo "<script language='JavaS cript1.2'>\n";
                        echo "<!-- begin \n";
                     echo "document.write ('<img src=\"images/swap/' + picnumber +'.jpg\"
                  width=\"320\" height=\"240\" border=\"0\" alt=\"Fitness Training
                  Image\">');\n";
                     echo "// end  -->\n";
                     echo "</script>"; }
                  >
                  but no avail.  still no pic shows up.
                  >
                  anyway.   i get really confused with all the nested stuff and single-double
                  quotes.  i may try that "heredoc" thing that Thomas suggested.  I'll need a
                  couple of beers first.   Friday night on Javascript?  Bad!
                  Do you have a link to what you're working on?

                  Also, a note on echoing HTML from PHP: If you need to selectively drop
                  bits of HTML, this could (just maybe) be a good idea, but usually it's
                  not. Outputting JavaScript that outputs HTML seems very round-about to
                  me. Especially because you're adding the image element in such an
                  obtrusive manner (rather than adding a DOM node and changing its
                  source programmaticall y).

                  Now, on to the functionality itself. As it stands now, you're relying
                  on JS to provide the randomness. Why do you want to do that if you
                  have access to PHP? The only reason I've done something like this is
                  because I was stuck in an HTML-only environment. Actually, I wrote a
                  script for a coworker today to exactly that because she had ot
                  implement the same thing in a Dreamweaver template. You can take a
                  look if you want: http://content.coprinstitute.org/lib...RandomImage.js

                  The comments are only a tiny bit out of date: I recently extended it
                  to also affect the image source (it originally was for background
                  image styles). The cool thing is that you can pass in as many
                  filenames as you want.

                  Call the function like this:

                  randomImage(tar get image, image folder, method, filename, filename,
                  filename...);

                  For example:

                  randomImage("im ageId", "/images", "src", "filename1.jpg" ,
                  "filename2.jpg" );

                  would randomly select one of these two images on the page load (if I
                  made it an onload event).

                  Thomas

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: nesting JS in echo's

                    Request-1 wrote:
                    "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                    news:gf2t4m$inr $1@registered.m otzarella.org.. .
                    >Request-1 wrote:
                    >>hi folks,
                    >>>
                    >>html coder here, new and terrified * of php!!
                    >>aaaaaa!
                    >>>
                    >>i'm trying to bury a JS script to rotate a photo, in a page i converted
                    >>from html to php.
                    >>the conversion went well, it was to use a php session cookie to stop the
                    >>repeating of an embedded video file on a per session basis;
                    >>i amended the php code to display a still pic if the session cookie value
                    >>was nil.
                    >>>
                    >>worked fine.
                    >>>
                    >>thought I'd try integrating a tested and true JS image random rotator
                    >>script into the echo command, but the problem was the syntax of the
                    >>single quotes and double quotes needed in the doc.write and variable
                    >>sequences in the JS.
                    >>>
                    >>i tried escaping the double quotes (my echo used double quotes), but to
                    >>no avail.
                    >>>
                    >>here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
                    >>variable holding the randomly assigned number that chooses the picture.
                    >>>
                    >>any help much appreciated..
                    >>>
                    >>>
                    >>+++++++++++++ +++
                    >>>
                    >>{ echo "
                    >>>
                    >> <script language='JavaS cript1.2'>
                    >> <!-- begin
                    >> document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
                    >> // end -->
                    >></script>
                    >> "; }
                    >>>
                    >>+++++++++++++ +++++++++++++
                    >>>
                    >>thanks
                    >You have an extra single quote before <img ...
                    >
                    >
                    >
                    Hi Jerry,
                    >
                    the single quote is actually necessary in JS when you're using
                    document.write to add strings in series (is it called "concatenat ing" or
                    something?). so the <img src...statement was broken down into 3 seperate
                    stings to be re-joined - all within the double-quote nested doc.write stmt.
                    my mistake was to leave the image path in single quotes; instead I tried
                    "escaped double quotes" to complete the image path, like so,
                    >
                    { echo "<script language='JavaS cript1.2'>\n";
                    echo "<!-- begin \n";
                    echo "document.write ('<img src=\"images/swap/' + picnumber +'.jpg\"
                    width=\"320\" height=\"240\" border=\"0\" alt=\"Fitness Training
                    Image\">');\n";
                    echo "// end -->\n";
                    echo "</script>"; }
                    >
                    >
                    but no avail. still no pic shows up.
                    >
                    anyway. i get really confused with all the nested stuff and single-double
                    quotes. i may try that "heredoc" thing that Thomas suggested. I'll need a
                    couple of beers first. Friday night on Javascript? Bad!
                    >
                    >
                    Yes, I'm familiar with concatenating and JS. I should have looked more
                    closely - I just saw the mismatched quotes and took the first one. Your
                    formatting and the word wrap makes your code harder to read.

                    So what do you get for js errors? Have you looked at the generated js code?

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: nesting JS in echo's

                      Request-1 wrote:
                      "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                      news:gf2t4m$inr $1@registered.m otzarella.org.. .
                      >Request-1 wrote:
                      >>hi folks,
                      >>>
                      >>html coder here, new and terrified * of php!!
                      >>aaaaaa!
                      >>>
                      >>i'm trying to bury a JS script to rotate a photo, in a page i converted
                      >>from html to php.
                      >>the conversion went well, it was to use a php session cookie to stop the
                      >>repeating of an embedded video file on a per session basis;
                      >>i amended the php code to display a still pic if the session cookie value
                      >>was nil.
                      >>>
                      >>worked fine.
                      >>>
                      >>thought I'd try integrating a tested and true JS image random rotator
                      >>script into the echo command, but the problem was the syntax of the
                      >>single quotes and double quotes needed in the doc.write and variable
                      >>sequences in the JS.
                      >>>
                      >>i tried escaping the double quotes (my echo used double quotes), but to
                      >>no avail.
                      >>>
                      >>here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
                      >>variable holding the randomly assigned number that chooses the picture.
                      >>>
                      >>any help much appreciated..
                      >>>
                      >>>
                      >>+++++++++++++ +++
                      >>>
                      >>{ echo "
                      >>>
                      >> <script language='JavaS cript1.2'>
                      >> <!-- begin
                      >> document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
                      >> // end -->
                      >></script>
                      >> "; }
                      >>>
                      >>+++++++++++++ +++++++++++++
                      >>>
                      >>thanks
                      >You have an extra single quote before <img ...
                      >
                      >
                      >
                      Hi Jerry,
                      >
                      the single quote is actually necessary in JS when you're using
                      document.write to add strings in series (is it called "concatenat ing" or
                      something?). so the <img src...statement was broken down into 3 seperate
                      stings to be re-joined - all within the double-quote nested doc.write stmt.
                      my mistake was to leave the image path in single quotes; instead I tried
                      "escaped double quotes" to complete the image path, like so,
                      >
                      { echo "<script language='JavaS cript1.2'>\n";
                      echo "<!-- begin \n";
                      echo "document.write ('<img src=\"images/swap/' + picnumber +'.jpg\"
                      width=\"320\" height=\"240\" border=\"0\" alt=\"Fitness Training
                      Image\">');\n";
                      echo "// end -->\n";
                      echo "</script>"; }
                      >
                      >
                      but no avail. still no pic shows up.
                      >
                      anyway. i get really confused with all the nested stuff and single-double
                      quotes. i may try that "heredoc" thing that Thomas suggested. I'll need a
                      couple of beers first. Friday night on Javascript? Bad!
                      >
                      >
                      BTW - you don't need quotes around numeric values like your width,
                      height and border. Only non-numeric data.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • Seni Seven

                        #12
                        Re: nesting JS in echo's

                        Jerry Stuckle <jstucklex@attg lobal.netwrote in comp.lang.php:
                        Request-1 wrote:
                        >"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                        >news:gf2t4m$in r$1@registered. motzarella.org. ..
                        >>Request-1 wrote:
                        >>>hi folks,
                        >>>>
                        >>>html coder here, new and terrified * of php!!
                        >>>aaaaaa!
                        >>>>
                        >>>i'm trying to bury a JS script to rotate a photo, in a page i
                        >>>converted from html to php.
                        >>>the conversion went well, it was to use a php session cookie to
                        >>>stop the repeating of an embedded video file on a per session
                        >>>basis; i amended the php code to display a still pic if the session
                        >>>cookie value was nil.
                        >>>>
                        >>>worked fine.
                        >>>>
                        >>>thought I'd try integrating a tested and true JS image random
                        >>>rotator script into the echo command, but the problem was the
                        >>>syntax of the single quotes and double quotes needed in the
                        >>>doc.write and variable sequences in the JS.
                        >>>>
                        >>>i tried escaping the double quotes (my echo used double quotes),
                        >>>but to no avail.
                        >>>>
                        >>>here's the JS CODE i use in the tail end of my PHP. "picnumber" is
                        >>>the variable holding the randomly assigned number that chooses the
                        >>>picture.
                        >>>>
                        >>>any help much appreciated..
                        >>>>
                        >>>>
                        >>>++++++++++++ ++++
                        >>>>
                        >>>{ echo "
                        >>>>
                        >>> <script language='JavaS cript1.2'>
                        >>> <!-- begin
                        >>> document.write( \"'<img src='images/swap/'+ picnumber +
                        >>> '.jpg'>\");
                        >>> // end -->
                        >>></script>
                        >>> "; }
                        >>>>
                        >>>++++++++++++ ++++++++++++++
                        >>>>
                        >>>thanks
                        >>You have an extra single quote before <img ...
                        >>
                        >>
                        >>
                        >Hi Jerry,
                        >>
                        >the single quote is actually necessary in JS when you're using
                        >document.wri te to add strings in series (is it called "concatenat ing"
                        >or something?). so the <img src...statement was broken down into 3
                        >seperate stings to be re-joined - all within the double-quote nested
                        >doc.write stmt. my mistake was to leave the image path in single
                        >quotes; instead I tried "escaped double quotes" to complete the image
                        >path, like so,
                        >>
                        >{ echo "<script language='JavaS cript1.2'>\n";
                        > echo "<!-- begin \n";
                        > echo "document.write ('<img src=\"images/swap/' + picnumber
                        > +'.jpg\"
                        >width=\"320\ " height=\"240\" border=\"0\" alt=\"Fitness Training
                        >Image\">');\n" ;
                        > echo "// end -->\n";
                        > echo "</script>"; }
                        >>
                        >>
                        >but no avail. still no pic shows up.
                        >>
                        >anyway. i get really confused with all the nested stuff and
                        >single-double quotes. i may try that "heredoc" thing that Thomas
                        >suggested. I'll need a couple of beers first. Friday night on
                        >Javascript? Bad!
                        >>
                        >>
                        >
                        BTW - you don't need quotes around numeric values like your width,
                        height and border. Only non-numeric data.
                        Are you talking about generating strict (X)HTML? Quotes must be on all
                        element attributes in that case, regardless of attribute value type.


                        Comment

                        • Curtis

                          #13
                          Re: nesting JS in echo's

                          On Sat, 08 Nov 2008 02:47:31 GMT, hello@you.com wrote:
                          >
                          "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          news:gf2t4m$inr $1@registered.m otzarella.org.. .
                          Request-1 wrote:
                          hi folks,
                          >
                          html coder here, new and terrified * of php!!
                          aaaaaa!
                          >
                          i'm trying to bury a JS script to rotate a photo, in a page i converted
                          from html to php.
                          the conversion went well, it was to use a php session cookie to stop the
                          repeating of an embedded video file on a per session basis;
                          i amended the php code to display a still pic if the session cookie value
                          was nil.
                          >
                          worked fine.
                          >
                          thought I'd try integrating a tested and true JS image random rotator
                          script into the echo command, but the problem was the syntax of the
                          single quotes and double quotes needed in the doc.write and variable
                          sequences in the JS.
                          >
                          i tried escaping the double quotes (my echo used double quotes), but to
                          no avail.
                          >
                          here's the JS CODE i use in the tail end of my PHP. "picnumber" is the
                          variable holding the randomly assigned number that chooses the picture.
                          >
                          any help much appreciated..
                          >
                          >
                          +++++++++++++++ +
                          >
                          { echo "
                          >
                          <script language='JavaS cript1.2'>
                          <!-- begin
                          document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
                          // end -->
                          </script>
                          "; }
                          >
                          +++++++++++++++ +++++++++++
                          >
                          thanks
                          You have an extra single quote before <img ...
                          >
                          >
                          >
                          Hi Jerry,
                          >
                          the single quote is actually necessary in JS when you're using
                          document.write to add strings in series (is it called "concatenat ing" or
                          something?).
                          Actually, you are not concatenating anything with the code Jerry
                          pointed out:
                          document.write( \"'<img src='images/swap/'+ picnumber + '.jpg'>\");
                          this results in:

                          document.write( "'<img src='images/swap/'+ picnumber + '.jpg'");

                          This is a single string of invalid HTML. You should have used double
                          quotes, not single, while also not using the initial single quote:

                          document.write( "<img src='images/swap/" + picnumber + ".jpg'>");

                          <ot>
                          You should also note that "document.write " doesn't function when
                          XHTML is served as application/xhtml+xml. It would also be much
                          cleaner if you used the DOM in the first place.
                          </ot>

                          [snip]
                          >
                          { echo "<script language='JavaS cript1.2'>\n";
                          echo "<!-- begin \n";
                          echo "document.write ('<img src=\"images/swap/' + picnumber +'.jpg\"
                          width=\"320\" height=\"240\" border=\"0\" alt=\"Fitness Training
                          Image\">');\n";
                          echo "// end -->\n";
                          echo "</script>"; }
                          Is there any particular reason you have this code in a block, or did
                          you not post enough code above it?

                          --
                          Curtis
                          $email = str_replace('si g.invalid', 'gmail.com', $from);

                          Comment

                          • Request-1

                            #14
                            Re: nesting JS in echo's

                            <ot>
                            You should also note that "document.write " doesn't function when
                            XHTML is served as application/xhtml+xml. It would also be much
                            cleaner if you used the DOM in the first place.
                            </ot>
                            >
                            [snip]
                            >>
                            >{ echo "<script language='JavaS cript1.2'>\n";
                            > echo "<!-- begin \n";
                            > echo "document.write ('<img src=\"images/swap/' + picnumber +'.jpg\"
                            >width=\"320\ " height=\"240\" border=\"0\" alt=\"Fitness Training
                            >Image\">');\n" ;
                            > echo "// end -->\n";
                            > echo "</script>"; }
                            >
                            Is there any particular reason you have this code in a block, or did
                            you not post enough code above it?
                            >
                            --
                            Curtis
                            $email = str_replace('si g.invalid', 'gmail.com', $from);
                            thanks to Curtis & 703 ...

                            ok, finally got it; the PHP "if" fork I used was fine:

                            { echo "<script language='JavaS cript1.2'>\n";
                            echo "<!-- begin \n";
                            echo "document.write ('<img src=\"images/swap/' + picnumber
                            +'.jpg\" width=\"320\" height=\"240\" border=\"0\"
                            alt=\"Fitness Training\">');\ n";
                            echo "// end -->\n";
                            echo "</script>"; }

                            but I made a mistake in "php-izing" the <headrandomizin g JS function. it
                            was fine to leave it in the orig JS.
                            Works like a charm now. Thanks to all for your input and finnicky
                            single-quote double-vision.

                            my original page that plays the intro video at every load is here:
                            bodymechanicsonline.com is your first and best source for information about bodymechanicsonline. Here you will also find topics relating to issues of general interest. We hope you find what you are looking for!


                            my experimental page that uses PHP session cookie to limit the video to 1st
                            load only, is here:


                            it's a little nerve-wracking but somewhat gratifying (!) to splice a little
                            PHP into a mostly-html page, call it by a php extension, and see it render
                            properly even tho' most of the page is not "echo'd" as per "proper" php.

                            anyway, i'm happy to live on Html Mountain; my brain flounder$ when it see$
                            too many dollar $igns ...


                            Comment

                            • Daniel Smedegaard Buus

                              #15
                              Re: nesting JS in echo's

                              Request-1 wrote:
                              >
                              >
                              >
                              thanks guys but no luck.
                              i'm swimming in single & double-quote-land.
                              >
                              >

                              I was thinking exactly the same as Thomas on this one. Echoing the stuff out
                              is only gonna complicate things and slow execution down. No reason you
                              shouldn't do

                              <?php
                              if ($something_or_ other) { ?>

                              <script type="text/javascript>
                              alert("What's up, baby? <?php echo "I mean, what's up? :)" ?>");
                              </script>

                              <?php }
                              // And on with the show...
                              ?>

                              Also, make sure you handle your cookies correctly. You can't create a cookie
                              and read it in the same script run. Also, make sure to specify the domain
                              and scope (".bodymechanic sonline.com"), or the cookie will exist for
                              http://bodymechanicsonline.com/ but not
                              http://www.bodymechanicsonline.com/, and vice versa. The new Firebug has
                              cookie support, makes it easy to debug.

                              HTH,
                              Daniel :)


                              Comment

                              Working...