Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 1, 2026.

Problem validating javascript with xhtml

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

gamex

Established Member
Impact
7
Problem validating javascript with xhtml - RESOLVED

I have a PHP function where I type in an email address and it will print out a javascript to display my email address to protect it from email harvesters.

The output looks like this:

<script type="text/javascript">
emailAddy='domain.com'
emailAddy=('someperson' + '@' + emailAddy)
document.write('<a href="mailto:' + emailAddy + '">' + emailAddy + '</a>')
</script>

However, when I validate the page at w3.org, I get this error:

Line 57, column 50: document type does not allow element "a" here

document.write('<a href="mailto:' + emailAddy + '">' + emailAddy + '</a>')

I made the greater than sign red because thats what the validator shows me. Any ideas?




EDIT: PROBLEM SOLVED!!!!

I spent half an hour trying to figure out a solution before I posted it, and of course, 10 minutes after I posted it, I figured it out. I just had to put put the comment tags inside my script :)

<script type="text/javascript">
<!--
emailAddy='domain.com'
emailAddy=('someperson' + '@' + emailAddy)
document.write('<a href="mailto:' + emailAddy + '">' + emailAddy + '</a>')
-->
</script>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Olitt — high-converting AI websites, only from $1/moOlitt — high-converting AI websites, only from $1/mo

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back