Forum Moderators: open

Message Too Old, No Replies

Javascript will not validated

Javascript within my web page will not validate.

         

neiltheblue

1:09 pm on Jan 19, 2007 (gmt 0)

10+ Year Member



I have a webpage named fader.php which consists of the following code to create a slideshow of images.

<snip>

i have this page being called through in my index page to create my rolling image. The problem is this fader.php page will not validate as it is shown in my source code of my index.php page. adding this code to a wep page will show how it does not validate.

Can anybody help in reasoning why.

[edited by: engine at 2:58 pm (utc) on Jan. 19, 2007]
[edit reason] FYI [webmasterworld.com] [/edit]

pageoneresults

1:15 pm on Jan 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<script language="JavaScript">

The language attribute has been deprecated. The above should be replaced with...

<script type="text/javascript">

neiltheblue

2:02 pm on Jan 19, 2007 (gmt 0)

10+ Year Member



thanks that took out 1 error for me. I still have 11 though which are caused by characters in the code itself. Any ideas. As you can see this is a piece of open source code so the code may be very loose.

pageoneresults

2:21 pm on Jan 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I still have 11 though which are caused by characters in the code itself. Any ideas?

I need to see what those 11 errors are. You can cut and paste them here for review. I'm going to guess that some of them are cascading so if we fix one, others will be fixed.

neiltheblue

2:32 pm on Jan 19, 2007 (gmt 0)

10+ Year Member



these are the errors from the validation not very clear i know

# Error Line 71 column 267: end tag for "SCRIPT" omitted, but its declaration does not permit this.

...ha(opacity=10);-moz-opacity:10"></div><div id="canvas1" style="position:absol

* You forgot to close a tag, or
* you used something inside this tag that was not allowed, and the validator is complaining that the tag should be closed before such content can be allowed.

The next message, "start tag was here" points to the particular instance of the tag in question); the positional indicator points to where the validator expected you to close the tag.

&#9993;
# Info Line 43 column 0: start tag was here.

<script type="text/javascript">

# Error Line 73 column 64: required attribute "ALT" not specified.

...ite('<img name="defaultslide" src="'+fadeimages[0]+'">')

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>.

&#9993;
# Error Line 91 column 60: required attribute "ALT" not specified.

tempobj.innerHTML='<img src="'+fadeimages[nextimageindex]+'">'

&#9993;
# Error Line 92 column 50: character ")" not allowed in attribute specification list.

nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0

&#9993;
# Error Line 92 column 50: element "FADEIMAGES.LENGTH-1" undefined.

nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0

You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by:

* incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "<frameset>" element),
* by using vendor proprietary extensions such as "<spacer>" or "<marquee>" (this is usually fixed by using CSS to achieve the desired effect instead).
* by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case.

&#9993;
# Error Line 107 column 48: character ")" not allowed in attribute specification list.

curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0

&#9993;
# Error Line 107 column 48: element "FADEIMAGES.LENGTH-1" undefined.

curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0

&#9993;
# Error Line 119 column 60: required attribute "ALT" not specified.

crossobj.innerHTML='<img src="'+fadeimages[curimageindex]+'">'

&#9993;
# Error Line 126 column 8: end tag for element "SCRIPT" which is not open.

</script>

The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

If this error occured in a script section of your document, you should probably read this FAQ entry.

&#9993;
# Error Line 162 column 5: end tag for element "DIV" which is not open.

</div>

&#9993;
# Error Line 176 column 5: end tag for element "DIV" which is not open.

</div>

The Contractor

2:43 pm on Jan 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Certain characters will never validate within a <tag>. Place your JavaScript into an external file and call it from there (which is always best). The alt text etetera means exactly that you need to have something like:

<img src="imagepath/name.gif" width="500" height="43" border="0" alt="">

neiltheblue

3:17 pm on Jan 19, 2007 (gmt 0)

10+ Year Member



the thing is i already have this piece of javascript in its own file called fader.php. This is then getting called in via php include within my index page.

The Contractor

3:28 pm on Jan 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you can have as many as you like.

Between your head tags you simply place:
<script src="path/name.js" type="text/javascript"></script>

Then call it from within your page. No need to create includes.

This way it will be cached and the visitor doesn't have to load all that code on each page.