[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 608
  • Last Modified:

Javascript causing validation failure becuase of tags in string vars

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
Coolhand2120
Asked:
Coolhand2120
  • 4
  • 2
  • 2
  • +2
1 Solution
 
jaysolomonCommented:
body onload = "resizeTo(x,y);document.title='blog';"
0
 
searlasCommented:
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
 
Coolhand2120Author 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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
devicCommented:
>>>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
 
DanRollinsCommented:
>>  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
 
devicCommented:
Dan, i thought about it, but it not works.
0
 
DanRollinsCommented:
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
 
Coolhand2120Author 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
0
 
Coolhand2120Author 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' )
0
 
Coolhand2120Author 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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now