Solved

Javascript causing validation failure becuase of tags in string vars

Posted on 2004-04-08
10
594 Views
Last Modified: 2012-05-04
I have an ASP application that uses a javascript popup window, because I use HTML tags in the script http://validator.w3.org/ validation fails with the error :

Line 1, column 37997: end tag for element "TITLE" which is not open
Line 1, column 38004: end tag for element "HEAD" which is not open
etc.

How can I avoid this invalid-validation?  Is there another way I can resize the window I open and set the title without actualy putting the strings "<title>,<body onload=" etc. into my script?

Here is the script in question
Sorry about the missing values for the ASP vars, the problem I'm having is about the general function, this script works but fails in http://validator.w3.org/ validation, and my goal is to get it to NOT fail validation.
------------------------------------------------------------------------------------------------------------------

response.write("<script  language=""JavaScript""  type=""text/javascript"">")
response.write("function showitem" & javaize(itemnumber) & "(){")
response.write("_w = window.open('','" & javaize(itemnumber) & "','width=" & popupwidth & ",height=" & popupheight & ",toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=2,left=7');")
response.write("_w.document.open();")
response.write("_w.document.write('<img style=""" & imgborder & """ src=""" & popupimage & """>');")
response.write("_w.document.write('<html><head><title>Item # " & ITEMNUMBER & "</title></head><body onload=""window.width = document.item.width;window.height = document.item.height;"">');")
response.write("_w.document.write('<br>');")
response.write("_w.document.write('<font size=""-1"" face=""" & font & """>');")
response.write("_w.document.write('" & capstring & "');")
response.write("_w.document.write('</font>');")
response.write("_w.document.write('<br>');")
response.write("_w.document.write('<input type=""button"" onclick=""javascript:window.close()"" value=""Close"">');")
response.write("_w.document.write('</body></html>');")
response.write("_w.document.close();")
response.write("};")
response.write("</script>")




-Coolhand2120
0
Comment
Question by:Coolhand2120
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10784618
body onload = "resizeTo(x,y);document.title='blog';"
0
 
LVL 7

Expert Comment

by:searlas
ID: 10784668
You should be able to insert wrap the script in HTML comments to stop it being parsed by the validator:
response.write("<script  language=""JavaScript""  type=""text/javascript"">")
response.write("<!--")
response.write("function showitem" & javaize(itemnumber) & "(){")
....
response.write("};")
response.write("// -->")
response.write("</script>")
0
 
LVL 2

Author Comment

by:Coolhand2120
ID: 10784928
searlas,
I still get a validation error - the validator for some reason still reads the strings in the script as HTML despite the <!-- --> enclosing the function, also I had to insert carriage returns ( response.write(vbcr) ) to keep it from outputting <!--function ....  and causing a JS error.

I know it's a silly thing to try and fix but that's my job.


jaysolomon,
I tried to implement your idea, by doing this...

line 6...
response.write("_w.document.write('<img style=""" & imgborder & """ src=""" & popupimage & """>');")
'removed! response.write("_w.document.write('<html><head><title>Item # " & ITEMNUMBER & "</title></head><body onload=""window.width = document.item.width;window.height = document.item.height;"">');")
response.write("" & javaize(itemnumber) & ".resizeTo(x,y);" & javaize(itemnumber) & ".title='" & ITEMNUMBER & "';")
response.write("_w.document.write('<br>');")

but now I get a JS error saying object expected.  I'm guessing this is because the window never popped up... ? I don’t know how to do what you suggested I guess.  Could explain where in the model I'm supposed to use resizeTo() and document.title (I think putting document.title would change the parrent window).  Keep in mind my goal is to either as searlas suggested, avoid invalidation, or to remove the tags <body><title><html>etc. from my script to avoid invalidation.

Sorry if I missunderstood anyone.


-Coolhand2120
0
 
LVL 25

Expert Comment

by:devic
ID: 10791843
>>>How can I avoid this invalid-validation?


put your function in externe file:
=======================
<script src="my_js_include.js"  language="JavaScript"  type="text/javascript"></script>
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 10792529
>>  because I use HTML tags in the script ... validation fails with the error...

I don't understand the situation at all, but that part should be easy.  Just break the HTML tags up in the script.  Instead of
      response.write('_w.document.write("<BODY>Hi there</body>")')
use, e.g.,
      response.write('_w.document.write("<B"  & "ODY>Hi there</b" & "ody>")')

-- Dan
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 25

Expert Comment

by:devic
ID: 10793087
Dan, i thought about it, but it not works.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 10794433
diagnostic:
Remove this line:
      response.write("<script  language=""JavaScript""  type=""text/javascript"">")
and this line
     response.write("</script>")

and eyeball the result.  Maybe you missed a quadruple quote mark somewhere or something like that.
0
 
LVL 2

Author Comment

by:Coolhand2120
ID: 10811206
Dan, your idea works. I guess I didn't make it clear I'm using ASP/VBSCRIPT, that’s what the response.write() and "" two doublequotes are for (escape double quote in vbscript), but all I have to do is take the idea of breaking apart the tags in client side javascript to keep the validator from reading the javascript's document.write() function as HTML.  Here is the "fixed" code.

devic, I think your solution would work, however because the popup window contains some values that are generated an item listing do...loop I would have to change the function to accept more values, and I'm not entirely sure it would work because it would rely heavily on the client computer to generate and call upon the script.  Dan's way is simpler to implement into the code that already exists.  But I can't say your solution is wrong, and you did submit your answer first, so please go here for your points http://oldlook.experts-exchange.com:8080/Web/Web_Languages/JavaScript/Q_20951977.html.

Thank you all for your help with this truly meaningless problem.

-Coolhand2120
0
 
LVL 2

Author Comment

by:Coolhand2120
ID: 10811214
Sorry forgot to post the code, for posterity :)


response.write("<script  language=""JavaScript""  type=""text/javascript"">")
response.write(vbcr)
response.write("<!--")
response.write(vbcr)
response.write("function showitem" & javaize(itemnumber) & "(){")
response.write("_w = window.open('','" & javaize(itemnumber) & "','width=" & popupwidth & ",height=" & popupheight & ",toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=2,left=7');")
response.write("_w.document.open();")
response.write("_w.document.write('<htm'+'l><hea'+'d><titl'+'e>Item # " & ITEMNUMBER & "<'+'/title></'+'head><'+'body onload=""window.width = document.item.width;window.height = document.item.height;"">');")
response.write("_w.document.write('<'+'img style=""" & imgborder & """ src=""" & popupimage & """>');")
response.write("_w.document.write('<'+'br>');")
response.write("_w.document.write('<'+'font size=""-1"" face=""" & font & """>');")
response.write("_w.document.write('" & capstring & "');")
response.write("_w.document.write('<'+'/font>');")
response.write("_w.document.write('<'+'br>');")
response.write("_w.document.write('<input type=""button"" onclick=""javascript:window.close()"" value=""Close"">');")
response.write("_w.document.write('<'+'/body><'+'/html>');")
response.write("_w.document.close();")
response.write("};")
response.write(vbcr)
response.write("// -->")
response.write(vbcr)
response.write("</script>")

-Coolhand2120


p.s. the validator still cought the tags until I broke apart the </A combonation (i.e. '<'+'/A' or '</'+'A' )
0
 
LVL 2

Author Comment

by:Coolhand2120
ID: 10811247
there was an error in the script, but I didn't have "show script errors" turned on, don't know how this slipped in there but this line

response.write("_w.document.write('<htm'+'l><hea'+'d><titl'+'e>Item # " & ITEMNUMBER & "<'+'/title></'+'head><'+'body onload=""window.width = document.item.width;window.height = document.item.height;"">');")

should read

response.write("_w.document.write('<htm'+'l><hea'+'d><titl'+'e>Item # " & ITEMNUMBER & "<'+'/title></'+'head><'+'body>');")


-Coolhand2120
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now