We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Javascript causing validation failure becuase of tags in string vars

Coolhand2120
Coolhand2120 asked
on
Medium Priority
629 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
Comment
Watch Question

body onload = "resizeTo(x,y);document.title='blog';"

Commented:
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>")

Author

Commented:
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
CERTIFIED EXPERT

Commented:
>>>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>
CERTIFIED EXPERT
Author of the Year 2009
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT

Commented:
Dan, i thought about it, but it not works.
CERTIFIED EXPERT
Author of the Year 2009

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

Author

Commented:
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

Author

Commented:
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' )

Author

Commented:
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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.