Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Validation Issues with MOD JavaScript code  (Read 2534 times)

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Validation Issues with MOD JavaScript code
« on: June 15, 2007, 03:53:38 am »

This thread is in relation to the Add CSS Tag buttons to admin panel MOD originally created by keyrocks and ported by alexanderpas.

Now, I have modified this MOD a fraction, to include language variables and clean up the code so it is formatted in the same way as other JavaScript functions within sNews1.6.01DE.  The problem is I cannot get it to validate.  NOTE:  the original MOD also did not validate, however with more errors (15).  I am now getting 9 validations errors with the below code but I do not know how to rectify them.  Therefore I am requesting assistance to rectify these issues.

Below is the code I am using for the JavaScript portion of this MOD:
Code: [Select]
case 'divid':
                url = prompt("", '');
if (url != null) {start = '
'; end = '<\/div>'; } else {start = end = '';}
break;
case 'divclass':
                url = prompt("", '');
if (url != null) {start = '
'; end = '<\/div>'; } else {start = end = '';}
break;
case 'spanclass':
                url = prompt("", '');
if (url != null) {start = ''; end = '<\/span>'; } else {start = end = '';}
break;
Now, when logged into sNews as Admin, if I then attempt to validate I receive the validation errors.
If you copy and paste the following code (below) into a file and save it as test.php, then use the Validate by File Upload option at W3C Markup Validator, you can see the errors I experience:
Code: [Select]



title










Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Validation Issues with MOD JavaScript code
« Reply #1 on: June 15, 2007, 06:12:35 am »

Here's your first problem (I haven't run the full html through the validator, just something I spotted here)
Quote from: mod html
title
(oopsie, two opening title tags for one closing and nothing in between? eeern! *optional: blinking red light*

Here's another problem (visavi: method) -- PHP is a server-side thing. You can't validate a PHP file through the W3C's File Upload validation... it has to be on a local or remote web server. So if that is the method of validation you're using, try another.

When the file test.php is placed on a web server and run through the validator, these are the errors I get:
Quote
Error Line 54 column 52: character "'" is not allowed in the value of attribute "id".
... if (url != null) {start = '
'; end = '<\/div>'; } else {sta
It is possible that you violated the naming convention for this attribute. For example, id and name attributes must begin with a letter, not a digit.


Error Line 54 column 60: document type does not allow element "div" here.
... != null) {start = '
'; end = '<\/div>'; } else {start = end
The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).
One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


Warning Line 54 column 71: character "<" is the first character of a delimiter but occurred as data.
...= null) {start = '
'; end = '<\/div>'; } else {start = end = '';}
This message may appear in several cases:
You tried to include the "<" character in your page: you should escape it as "<"
You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe.
Another possibility is that you forgot to close quotes in a previous tag.



Warning Line 58 column 74: character "<" is the first character of a delimiter but occurred as data.
...) {start = '
'; end = '<\/div>'; } else {start = end = '';}


Warning Line 62 column 75: character "<" is the first character of a delimiter but occurred as data.
...{start = ''; end = '<\/span>'; } else {start = end = '';}


Error Line 79 column 46: character "\" not allowed in attribute specification list.
            case 'br': start = ''; end = '
'; break;


Error Line 79 column 47: end tag for "br" omitted, but OMITTAG NO was specified.
            case 'br': start = ''; end = '
'; break;
You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".


Info Line 79 column 42: start tag was here.
            case 'br': start = ''; end = '
'; break;
Error Line 84 column 72: character "\" not allowed in attribute specification list.
... != null ? ''+alt+'' : '';


Error Line 84 column 73: end tag for "img" omitted, but OMITTAG NO was specified.
...= null ? ''+alt+'' : '';


Info Line 84 column 39: start tag was here.
                start = url != null ? ''+alt+'' : .
Warning Line 91 column 89: character "<" is the first character of a delimiter but occurred as data.
...'+url+'" title="'+title+'">'; end = '<\/a>';}


Warning Line 95 column 30: character "<" is the first character of a delimiter but occurred as data.
            default: start = '<'+tag+'>'; end = '<\/'+tag+'>';


Warning Line 95 column 49: character "<" is the first character of a delimiter but occurred as data.
            default: start = '<'+tag+'>'; end = '<\/'+tag+'>';


Warning Line 100 column 31: character "<" is the first character of a delimiter but occurred as data.
            if(selected.length <= 0) {src.value += start + title + end;}


Error Line 126 column 12: end tag for "a" omitted, but OMITTAG NO was specified.
   


Info Line 91 column 43: start tag was here.
...          if (url != null) {start = ''; e
Error Line 126 column 12: end tag for "span" omitted, but OMITTAG NO was specified.
   


Info Line 62 column 43: start tag was here.
...          if (url != null) {start = ''; end = '<\/span>
Error Line 126 column 12: end tag for "div" omitted, but OMITTAG NO was specified.
   


Info Line 58 column 43: start tag was here.
...          if (url != null) {start = '
'; end = '<\/div>';
Error Line 126 column 12: end tag for "div" omitted, but OMITTAG NO was specified.
   


Info Line 54 column 43: start tag was here.
...          if (url != null) {start = '
'; end = '<\/div>'; }
Are those the errors you mean? Most of them seem self explanatory. How to fix them though -- sorry. I don't have any good advice to offer, other than escaping your html entities. That will at least eliminate some of the errors, but could also lead to new errors being detected (sometimes the validator stops where it finds the first error and doesn't report subsequent errors on the same line. Fixing one error may lead to the validator reporting "new" errors that it didn't report first time around. Yeah, loads of fun. ;)

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Validation Issues with MOD JavaScript code
« Reply #2 on: June 15, 2007, 08:09:11 am »

Quote from: agentsmith
Here's your first problem (I haven't run the full html through the validator, just something I spotted here)
Quote from: mod html
title
(oopsie, two opening title tags for one closing and nothing in between? eeern! *optional: blinking red light*
Umm, what?  You may want to look at that a little more closely smitty, you even quoted it correctly!!!

Quote
When the file test.php is placed on a web server and run through the validator, these are the errors I get:
Quote
... lots of errors ...
Are those the errors you mean?
Yup, them's the errors i be encountered with.

A question, should JavaScript validate anyway??  I mean does the validator interpret JavaScript correctly?
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

Joost

  • Guest
Validation Issues with MOD JavaScript code
« Reply #3 on: June 15, 2007, 03:00:10 pm »

Quote from: piXelatedEmpire
A question, should JavaScript validate anyway??  I mean does the validator interpret JavaScript correctly?
No,  in xhtml you cannot use javascript with +, - and lots of other stuff. Unless you use this
Code: [Select]
// //]]>You can also put it in a external js file. Function calls are valid if I am not mistaken.
Logged

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Validation Issues with MOD JavaScript code
« Reply #4 on: June 16, 2007, 06:39:36 am »

Terrific Joost, problem solved!  I must have removed those lines from my snews.php for some silly reason.  Thanks heaps!
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future