SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Syntax for <script> within PHP (for validation)

    Hope someone can help with this.

    I've basically been checking my validation for a site, and have a page with a single error :

    <SCRIPT>

    The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

    Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.

    I think I've figured out its due to the PHP code that starts :

    Code:
    <?php
    if ($row_rsModels)     {
      echo "<SC" . "RIPT>\n";
      echo "var WAJA = new Array();\n";
    
      $oldmainid = 0;
      $newmainid = $row_rsModels["Make"];
      if ($oldmainid == $newmainid)    {
        $oldmainid = "";
      }
    ie the echo "<SC" . "RIPT>\n"; line

    How would I incorporate the type="text/css" part in there for it to validate?

    I've tried a few things, but presumably just have the syntax wrong.

    If anyone could point me in the right direction, that would be much appreciated.

    Thanks.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Who knows why that line has been cut in two
    Anyhow, try this
    Code PHP:
    echo "<SCRIPT type=\"text/javascript\">\n";

  3. #3
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Better not to mess with PHP syntax at all. Just escape it
    PHP Code:
    <?php
    if ($row_rsModels)     {
    ?>
    <SCRIPT type="text/javascript">
      var WAJA = new Array();
    <?
      $oldmainid 
    0;
      
    $newmainid $row_rsModels["Make"];
      if (
    $oldmainid == $newmainid)    {
        
    $oldmainid "";
      }
    ?>

  4. #4
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!

  5. #5
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    Better not to mess with PHP syntax at all. Just escape it
    PHP Code:
    <?php
    if ($row_rsModels)     {
    ?>
    <SCRIPT type="text/javascript">
      var WAJA = new Array();
    <?
      $oldmainid 
    0;
      
    $newmainid $row_rsModels["Make"];
      if (
    $oldmainid == $newmainid)    {
        
    $oldmainid "";
      }
    ?>
    Good point.
    Don't mess any code like (javascript, css, html) with PHP.
    Always make a separation with opening & closing tags like Shrapnel_N5 has presented.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,820
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You need to be extra careful when using script tags in pages being parsed by PHP to make sure that it can properly distinguish between

    <script type="text/javascript">

    and

    <script language="php">
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •