cut 'n paste Javascript into BODY & getting it to validate

R

rfr

I use cut 'n paste Javascripts.

The validators dont like these.

I found that, for those which are loaded in the <head></head> that the
simple process of linking it from an external file seems to validate and the
JS works.

But, what do I do when the Javascript needs to be in the BODY, not in the
HEADER?

I am not sure if any browsers will link in an external Javascript that is
evoked between the <BODY> and </BODY> markers.

Any suggestions on how to get this JS to validate?
 
R

rfr

I am still in development mode and all the material is still on my PC.

Even at this point, I can see that while it works well in MSIE, it doesnt in
netscape, Firefox and Opera.

So, my usual proceedure to deal with this is to validate the HTML and CSS.

While it would be too volumous to copy/paste the entire document code here,
here is partial code that exists just following the <BODY> marker, between
the equal signs;
======================================
<div ID="content" style="width:1000px;background-color:ivory;border:1px
solid black;">
<!--webbot bot="Include" U-Include="_std_header.htm" TAG="BODY" --><br>
<script type="text/javascript">

/***********************************************
* Conveyor belt slideshow script- © Dynamic Drive DHTML code library
(www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/


//Specify the slider's width (in pixels)
var sliderwidth="900px"
//Specify the slider's height
var sliderheight="100px"
//Specify the slider's slide speed (larger is faster 1-10)
var slidespeed=2
//configure background color:
slidebgcolor="#F0F8FF"

//Specify the slider's images
var leftrightslide=new Array()
var finalslide=''
leftrightslide[0]='<a href="index.htm"> <img
src="thumbs/front_cover_thumb.jpg" border=1></a>'
leftrightslide[1]='<a href="panel_01.htm"> <img
src="thumbs/front_inside_thumb.jpg" border=1></a>'
leftrightslide[2]='<a href="panel_01.htm"><img
src="thumbs/page_01_thumb.jpg" border=1></a>'
leftrightslide[3]='<a href="panel_02.htm"><img
src="thumbs/page_02_thumb.jpg" border=1></a>'
leftrightslide[4]='<a href="panel_02.htm"><img
src="thumbs/page_03_thumb.jpg" border=1></a>'
leftrightslide[5]='<a href="panel_03.htm"><img
src="thumbs/page_04_thumb.jpg" border=1></a>'
leftrightslide[6]='<a href="panel_03.htm"><img
src="thumbs/page_05_thumb.jpg" border=1></a>'
leftrightslide[7]='<a href="panel_04.htm"><img
src="thumbs/page_06_thumb.jpg" border=1></a>'
leftrightslide[8]='<a href="panel_04.htm"><img
src="thumbs/page_07_thumb.jpg" border=1></a>'
leftrightslide[9]='<a href="panel_05.htm"><img
src="thumbs/page_08_thumb.jpg" border=1></a>'
leftrightslide[10]='<a href="panel_05.htm"><img
src="thumbs/page_09_thumb.jpg" border=1></a>'
leftrightslide[11]='<a href="panel_06.htm"><img
src="thumbs/page_10_thumb.jpg" border=1></a>'
leftrightslide[12]='<a href="panel_06.htm"><img
src="thumbs/page_11_thumb.jpg" border=1></a>'
leftrightslide[13]='<a href="panel_07.htm"><img
src="thumbs/page_12_thumb.jpg" border=1></a>'
leftrightslide[14]='<a href="panel_07.htm"><img
src="thumbs/page_13_thumb.jpg" border=1></a>'
leftrightslide[15]='<a href="panel_08.htm"><img
src="thumbs/page_14_thumb.jpg" border=1></a>'
leftrightslide[16]='<a href="panel_08.htm"><img
src="thumbs/page_15_thumb.jpg" border=1></a>'
leftrightslide[17]='<a href="panel_09.htm"><img
src="thumbs/page_16_thumb.jpg" border=1></a>'
leftrightslide[18]='<a href="panel_10.htm"><img
src="thumbs/page_17_thumb.jpg" border=1></a>'
leftrightslide[19]='<a href="panel_10.htm"><img
src="thumbs/page_18_thumb.jpg" border=1></a>'
leftrightslide[20]='<a href="panel_11.htm"><img
src="thumbs/page_19_thumb.jpg" border=1></a>'
leftrightslide[21]='<a href="panel_11.htm"><img
src="thumbs/page_20_thumb.jpg" border=1></a>'
leftrightslide[22]='<a href="panel_12.htm"><img
src="thumbs/page_21_thumb.jpg" border=1></a>'
leftrightslide[23]='<a href="panel_12.htm"><img
src="thumbs/page_22_thumb.jpg" border=1></a>'
leftrightslide[24]='<a href="panel_13.htm"><img
src="thumbs/page_23_thumb.jpg" border=1></a>'
leftrightslide[25]='<a href="panel_13.htm"><img
src="thumbs/page_24_thumb.jpg" border=1></a>'
leftrightslide[26]='<a href="panel_14.htm"><img
src="thumbs/page_24xa_thumb.jpg" border=1></a>'
leftrightslide[27]='<a href="panel_14.htm"><img
src="thumbs/page_24xb_thumb.jpg" border=1></a>'
leftrightslide[28]='<a href="panel_15.htm"><img
src="thumbs/page_25_thumb.jpg" border=1></a>'
leftrightslide[29]='<a href="panel_15.htm"><img
src="thumbs/page_26_thumb.jpg" border=1></a>'
leftrightslide[30]='<a href="panel_16.htm"><img
src="thumbs/page_27_thumb.jpg" border=1></a>'
leftrightslide[31]='<a href="panel_16.htm"><img
src="thumbs/page_28_thumb.jpg" border=1></a>'
leftrightslide[32]='<a href="panel_17.htm"><img
src="thumbs/page_29_thumb.jpg" border=1></a>'
leftrightslide[33]='<a href="panel_17.htm"><img
src="thumbs/page_30_thumb.jpg" border=1></a>'
leftrightslide[34]='<a href="panel_18.htm"><img
src="thumbs/page_31_thumb.jpg" border=1></a>'












//Specify gap between each image (use HTML):
var imagegap=""

//Specify pixels gap between each slideshow rotation (use integer):
var slideshowgap=3


////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=slidespeed
leftrightslide='<nobr>'+leftrightslide.join(imagegap)+'</nobr>'
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp"
style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+leftrightslide+'</span>')
var actualwidth=''
var cross_slide, ns_slide

function fillup(){
if (iedom){
cross_slide=document.getElementById? document.getElementById("test2") :
document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") :
document.all.test3
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
actualwidth=document.all? cross_slide.offsetWidth :
document.getElementById("temp").offsetWidth
cross_slide2.style.left=actualwidth+slideshowgap+"px"
}
else if (document.layers){
ns_slide=document.ns_slidemenu.document.ns_slidemenu2
ns_slide2=document.ns_slidemenu.document.ns_slidemenu3
ns_slide.document.write(leftrightslide)
ns_slide.document.close()
actualwidth=ns_slide.document.width
ns_slide2.left=actualwidth+slideshowgap
ns_slide2.document.write(leftrightslide)
ns_slide2.document.close()
}
lefttime=setInterval("slideleft()",30)
}
window.onload=fillup

function slideleft(){
if (iedom){
if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px"
else
cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+slideshowgap+"px"

if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px"
else
cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+slideshowgap+"px"

}
else if (document.layers){
if (ns_slide.left>(actualwidth*(-1)+8))
ns_slide.left-=copyspeed
else
ns_slide.left=ns_slide2.left+actualwidth+slideshowgap

if (ns_slide2.left>(actualwidth*(-1)+8))
ns_slide2.left-=copyspeed
else
ns_slide2.left=ns_slide.left+actualwidth+slideshowgap
}
}


if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div
style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden;">')
write('<div
style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';background-color:'+slidebgcolor+'"
onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed">')
write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
write('<div id="test3"
style="position:absolute;left:-1000px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+sliderwidth+' height='+sliderheight+'
name="ns_slidemenu" bgColor='+slidebgcolor+'>')
write('<layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0"
onMouseout="copyspeed=slidespeed"></layer>')
write('<layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0"
onMouseout="copyspeed=slidespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script>
====================================

As an example of the type of validation errors from the W3C HTML validator,
I get lots of these triggered by the Javascript;
=============================================
Line 114, Column 94: end tag for element "A" which is not open .
..s/front_cover_thumb.jpg" border=1></a>' Line 235, Column 12: end tag for
element "DIV" which is not open . write('</div></div>') Line 238, Column 66:
there is no attribute "NAME" . .width+' height='+sliderheight+'
name="ns_slidemenu" bgColor='+slidebgcolor+'."Kathleen Anderson"
 
M

Mike Mueller

It look like this is the source of your info:
http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm
Try validating that page, lots of errors on it

What I would do is to make up a simple mockup first, axeing most of the
content and just use 2 or 3 images for the presentation. Track down where
there errors are in that and once that works and validates, then you put it
into your main page and add the other dozen or so images

rfr said:
I am still in development mode and all the material is still on my PC.

Even at this point, I can see that while it works well in MSIE, it doesnt
in netscape, Firefox and Opera.

So, my usual proceedure to deal with this is to validate the HTML and CSS.

While it would be too volumous to copy/paste the entire document code
here, here is partial code that exists just following the <BODY> marker,
between the equal signs;
======================================
<div ID="content" style="width:1000px;background-color:ivory;border:1px
solid black;">
<!--webbot bot="Include" U-Include="_std_header.htm" TAG="BODY" --><br>
<script type="text/javascript">

/***********************************************
* Conveyor belt slideshow script- © Dynamic Drive DHTML code library
(www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/


//Specify the slider's width (in pixels)
var sliderwidth="900px"
//Specify the slider's height
var sliderheight="100px"
//Specify the slider's slide speed (larger is faster 1-10)
var slidespeed=2
//configure background color:
slidebgcolor="#F0F8FF"

//Specify the slider's images
var leftrightslide=new Array()
var finalslide=''
leftrightslide[0]='<a href="index.htm"> <img
src="thumbs/front_cover_thumb.jpg" border=1></a>'
leftrightslide[1]='<a href="panel_01.htm"> <img
src="thumbs/front_inside_thumb.jpg" border=1></a>'
leftrightslide[2]='<a href="panel_01.htm"><img
src="thumbs/page_01_thumb.jpg" border=1></a>'
leftrightslide[3]='<a href="panel_02.htm"><img
src="thumbs/page_02_thumb.jpg" border=1></a>'
leftrightslide[4]='<a href="panel_02.htm"><img
src="thumbs/page_03_thumb.jpg" border=1></a>'
leftrightslide[5]='<a href="panel_03.htm"><img
src="thumbs/page_04_thumb.jpg" border=1></a>'
leftrightslide[6]='<a href="panel_03.htm"><img
src="thumbs/page_05_thumb.jpg" border=1></a>'
leftrightslide[7]='<a href="panel_04.htm"><img
src="thumbs/page_06_thumb.jpg" border=1></a>'
leftrightslide[8]='<a href="panel_04.htm"><img
src="thumbs/page_07_thumb.jpg" border=1></a>'
leftrightslide[9]='<a href="panel_05.htm"><img
src="thumbs/page_08_thumb.jpg" border=1></a>'
leftrightslide[10]='<a href="panel_05.htm"><img
src="thumbs/page_09_thumb.jpg" border=1></a>'
leftrightslide[11]='<a href="panel_06.htm"><img
src="thumbs/page_10_thumb.jpg" border=1></a>'
leftrightslide[12]='<a href="panel_06.htm"><img
src="thumbs/page_11_thumb.jpg" border=1></a>'
leftrightslide[13]='<a href="panel_07.htm"><img
src="thumbs/page_12_thumb.jpg" border=1></a>'
leftrightslide[14]='<a href="panel_07.htm"><img
src="thumbs/page_13_thumb.jpg" border=1></a>'
leftrightslide[15]='<a href="panel_08.htm"><img
src="thumbs/page_14_thumb.jpg" border=1></a>'
leftrightslide[16]='<a href="panel_08.htm"><img
src="thumbs/page_15_thumb.jpg" border=1></a>'
leftrightslide[17]='<a href="panel_09.htm"><img
src="thumbs/page_16_thumb.jpg" border=1></a>'
leftrightslide[18]='<a href="panel_10.htm"><img
src="thumbs/page_17_thumb.jpg" border=1></a>'
leftrightslide[19]='<a href="panel_10.htm"><img
src="thumbs/page_18_thumb.jpg" border=1></a>'
leftrightslide[20]='<a href="panel_11.htm"><img
src="thumbs/page_19_thumb.jpg" border=1></a>'
leftrightslide[21]='<a href="panel_11.htm"><img
src="thumbs/page_20_thumb.jpg" border=1></a>'
leftrightslide[22]='<a href="panel_12.htm"><img
src="thumbs/page_21_thumb.jpg" border=1></a>'
leftrightslide[23]='<a href="panel_12.htm"><img
src="thumbs/page_22_thumb.jpg" border=1></a>'
leftrightslide[24]='<a href="panel_13.htm"><img
src="thumbs/page_23_thumb.jpg" border=1></a>'
leftrightslide[25]='<a href="panel_13.htm"><img
src="thumbs/page_24_thumb.jpg" border=1></a>'
leftrightslide[26]='<a href="panel_14.htm"><img
src="thumbs/page_24xa_thumb.jpg" border=1></a>'
leftrightslide[27]='<a href="panel_14.htm"><img
src="thumbs/page_24xb_thumb.jpg" border=1></a>'
leftrightslide[28]='<a href="panel_15.htm"><img
src="thumbs/page_25_thumb.jpg" border=1></a>'
leftrightslide[29]='<a href="panel_15.htm"><img
src="thumbs/page_26_thumb.jpg" border=1></a>'
leftrightslide[30]='<a href="panel_16.htm"><img
src="thumbs/page_27_thumb.jpg" border=1></a>'
leftrightslide[31]='<a href="panel_16.htm"><img
src="thumbs/page_28_thumb.jpg" border=1></a>'
leftrightslide[32]='<a href="panel_17.htm"><img
src="thumbs/page_29_thumb.jpg" border=1></a>'
leftrightslide[33]='<a href="panel_17.htm"><img
src="thumbs/page_30_thumb.jpg" border=1></a>'
leftrightslide[34]='<a href="panel_18.htm"><img
src="thumbs/page_31_thumb.jpg" border=1></a>'












//Specify gap between each image (use HTML):
var imagegap=""

//Specify pixels gap between each slideshow rotation (use integer):
var slideshowgap=3


////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=slidespeed
leftrightslide='<nobr>'+leftrightslide.join(imagegap)+'</nobr>'
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp"
style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+leftrightslide+'</span>')
var actualwidth=''
var cross_slide, ns_slide

function fillup(){
if (iedom){
cross_slide=document.getElementById? document.getElementById("test2") :
document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") :
document.all.test3
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
actualwidth=document.all? cross_slide.offsetWidth :
document.getElementById("temp").offsetWidth
cross_slide2.style.left=actualwidth+slideshowgap+"px"
}
else if (document.layers){
ns_slide=document.ns_slidemenu.document.ns_slidemenu2
ns_slide2=document.ns_slidemenu.document.ns_slidemenu3
ns_slide.document.write(leftrightslide)
ns_slide.document.close()
actualwidth=ns_slide.document.width
ns_slide2.left=actualwidth+slideshowgap
ns_slide2.document.write(leftrightslide)
ns_slide2.document.close()
}
lefttime=setInterval("slideleft()",30)
}
window.onload=fillup

function slideleft(){
if (iedom){
if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px"
else
cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+slideshowgap+"px"

if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px"
else
cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+slideshowgap+"px"

}
else if (document.layers){
if (ns_slide.left>(actualwidth*(-1)+8))
ns_slide.left-=copyspeed
else
ns_slide.left=ns_slide2.left+actualwidth+slideshowgap

if (ns_slide2.left>(actualwidth*(-1)+8))
ns_slide2.left-=copyspeed
else
ns_slide2.left=ns_slide.left+actualwidth+slideshowgap
}
}


if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div
style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden;">')
write('<div
style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';background-color:'+slidebgcolor+'"
onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed">')
write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
write('<div id="test3"
style="position:absolute;left:-1000px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+sliderwidth+' height='+sliderheight+'
name="ns_slidemenu" bgColor='+slidebgcolor+'>')
write('<layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0"
onMouseout="copyspeed=slidespeed"></layer>')
write('<layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0"
onMouseout="copyspeed=slidespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script>
====================================

As an example of the type of validation errors from the W3C HTML
validator, I get lots of these triggered by the Javascript;
=============================================
Line 114, Column 94: end tag for element "A" which is not open .
.s/front_cover_thumb.jpg" border=1></a>' Line 235, Column 12: end tag for
element "DIV" which is not open . write('</div></div>') Line 238, Column
66: there is no attribute "NAME" . .width+' height='+sliderheight+'
name="ns_slidemenu" bgColor='+slidebgcolor+'."Kathleen Anderson"
Can you post a link to a page where you've done this and it doesn't
validate?

--

~ Kathleen Anderson
Microsoft MVP - FrontPage
Spider Web Woman Designs
Expression Web Resources: http://www.spiderwebwoman.com/xweb/
FrontPage Resources: http://www.spiderwebwoman.com/resources/
Please reply to the newsgroup for the benefit of others
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top