SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Nov 19, 2009, 07:23 #1
- 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 = ""; }
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.
-
Nov 19, 2009, 07:28 #2
Who knows why that line has been cut in two
Anyhow, try this
Code PHP:echo "<SCRIPT type=\"text/javascript\">\n";
Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
-
Nov 19, 2009, 07:33 #3
- 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 = "";
}
?>
-
Nov 19, 2009, 09:24 #4
- Join Date
- Aug 2006
- Posts
- 375
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks guys!
-
Nov 19, 2009, 09:44 #5
-
Nov 19, 2009, 12:37 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- 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