Error: character "<" is the first character of a delimiter but occurred as data

I have tried to validate my page http://jimpix.co.uk/

But get this error 5 times:
character “<” is the first character of a delimiter but occurred as data

But I need the “<” in place in some javascript on the page:

function prev_my_photo() {
	MyPhotoThingVar--;

	if (MyPhotoThingVar <= 0) {
		MyPhotoThingVar = 0
	}

	return MyPhotoThingVar;
}

I need to have the javascript on the same page, and not as an include, because the ASP code includes the values it is checking against, so I can’t include the javascript, otherwise it won’t work.

Is this something I’ll have to live with? I can’t replace the “<” with an “<” because then the javascript breaks.

Thanks

Jim

Wrap your javascript like this to make it compatible with xhtml:


<script type="text/javascript">
//<![CDATA[

// rest of your javascript goes here

//]]>
</script>

Thanks fredda! That worked a treat.

Not if you serve your XHTML markup as XHTML. If you’re using pretend-XHTML you really should keep all JavaScript in external files, since the content type of the script element differs between HTML4 and XHTML1.

How would you get the following code to validate as xhtml 1.0 strict then?

<link rel=“stylesheet” type=“text/css” media=“screen” title=“User Defined Style” href=“<?php echo (!$_COOKIE[“sitestyle”])?‘default’:$_COOKIE[“sitestyle”]?>.css” />

Remove the title attribute and it should validate fine.


<link rel="stylesheet" type="text/css" media="screen" href="<?php echo (!$_COOKIE["sitestyle"])?'default':$_COOKIE["sitestyle"]?>.css" />

Hello Fredda

thank you for replying. Unfortunately, it does not solve the problem. It has something to do with ‘<’ and ‘>’. as in the javascript problem above.

What error message to you get when you validate?

Also how does your XHTML code look when you do view source in your browser?

I get the same error message as the original enquirer had - although his related to JavaScript and not php:

character “<” is the first character of a delimiter but occurred as data

The title attribute is perfectly fine. :slight_smile:

You’re not trying to validate the .php file itself, are you? That won’t fly. You can only validate the generated HTML or XHTML document.