locked
HTML question RRS feed

  • Question

  • Hey sorry if it's the wrong forum,

    I've got a very simple question, any idea why this line of code gets error on w3.org?

    <p style="text-align:center;"><a href="javascript:void(0);" ID="Blah" onClick=window.open("http://www.blah.com/images/blah.jpg","blah","width=680,height=510,scrollbars=1,resizable=0,toolbar=0,status=0,")><img src="images/blah.jpg" width="128" height="96" alt=""></a></p>

    Error: " in an unquoted attribute value. Probable causes: Attributes running together or a URL query string in an unquoted attribute value.

    • Moved by litdev Wednesday, July 22, 2020 9:27 AM
    Wednesday, July 22, 2020 9:06 AM

Answers

  • Attributes require a string literal. They can be specified as quoted (" or ') or unquoted literals.

    E.g. <a href="" ID="Blah"> is equivalent to <a href="" ID=Blah>.

    Using unquoted literals requires that the literal itself does not contain quotes or spaces. Otherwise parsing would be really hard.

    Thus you need to quote your onClick literal. This should do it:

    <p style="text-align:center;">
    	<a href="javascript:void(0);" ID="Blah" onClick="window.open('http://www.blah.com/images/blah.jpg','blah','width=680,height=510,scrollbars=1,resizable=0,toolbar=0,status=0,')">
    		<img src="images/blah.jpg" width="128" height="96" alt="">
    	</a>
    </p>
    

    • Marked as answer by OSVBNET Friday, July 24, 2020 6:11 PM
    Wednesday, July 22, 2020 9:57 AM

All replies

  • Attributes require a string literal. They can be specified as quoted (" or ') or unquoted literals.

    E.g. <a href="" ID="Blah"> is equivalent to <a href="" ID=Blah>.

    Using unquoted literals requires that the literal itself does not contain quotes or spaces. Otherwise parsing would be really hard.

    Thus you need to quote your onClick literal. This should do it:

    <p style="text-align:center;">
    	<a href="javascript:void(0);" ID="Blah" onClick="window.open('http://www.blah.com/images/blah.jpg','blah','width=680,height=510,scrollbars=1,resizable=0,toolbar=0,status=0,')">
    		<img src="images/blah.jpg" width="128" height="96" alt="">
    	</a>
    </p>
    

    • Marked as answer by OSVBNET Friday, July 24, 2020 6:11 PM
    Wednesday, July 22, 2020 9:57 AM
  • Hello,

    you could ask here: https://stackoverflow.com/questions/tagged/html+javascript

    Regards, Guido

    Wednesday, July 22, 2020 12:01 PM
  • In the onClick you need to use quotes (either single or double). E.g.

    <p style="text-align:center;"> <a href="javascript:void(0);" ID="Blah"

    onClick='window.open("http://www.blah.com/images/blah.jpg","blah","width=680,height=510,scrollbars=1,resizable=0,toolbar=0,status=0,")'><img src="images/blah.jpg" width="128" height="96" alt=""></a></p>

    Since you already have double quotes you may want to use single for the whole onClick method.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles


    • Edited by Naomi N Wednesday, July 22, 2020 12:37 PM
    Wednesday, July 22, 2020 12:35 PM