help with validation error in javascript

liunx

Guest
I use the following for email links; I picked up it from one of the javascript websites.<br />
<br />
<script type="text/javascript"><!--<br />
var name = "name"<br />
var domain = "domain"<br />
var suffix = "com"<br />
document.write("<a href='http://www.htmlforums.com/archive/index.php/mailto:" + name + "@" + domain + "." + suffix +"'>")<br />
document.write("My Email Address")<br />
document.write("</a>")<br />
//--><br />
</script><br />
<br />
Whenever I submit a page with that script in it for validation, it throws an error: <br />
<br />
<br />
Line 97, column 27: end tag for element "A" which is not open (explain...). <br />
document.write("</a>")<br />
<br />
Is there a better/more correct way to put my mailto links like this? <br />
<br />
2nd question: should the @ sign be character coded within the script?<br />
Thanks for your help.<!--content-->2nd question: should the @ sign be character coded within the script?<br />
<br />
i think the @ sign is causing your problems.<br />
<br />
change it to the character code and i think it will work.<br />
<br />
i dont know what the character code for '@' is though sorry mate<br />
<br />
edit: found it @ lol that didnt quite work<br />
<br />
& # 6 4 ; without any spaces though<!--content-->& # 6 4 ;<br />
<br />
added spaces so it won't show.<br />
<br />
Thanks joe2kiss, but it didn't stop the </a> error...<!--content-->.<br />
<br />
& # 4 6 ; for the . period<br />
<br />
also noticing you have a ' in your code<br />
<br />
document.write("<a href='http://www.htmlforums.com/archive/index.php/mailto:" + name + "@" + domain + "." + suffix +"'>")<br />
<br />
im not sure on javascript but i know HTML and im sure thats not supposed to be there<!--content-->Line 97, column 27: end tag for element "A" which is not open (explain...).<br />
document.write("</a>")<br />
<br />
<br />
I know i've gotten that error before when I didn't put quotes around url in my href=http://www.htmlforums.com/archive/index.php/"". I'm not sure with javascript though...<!--content-->I'm a novice at javascript, but I think the single quotation mark after the href='http://www.htmlforums.com/archive/index.php/is the first of two, the second is at the end of the mailto line. I think the single quotes are there because they're replacing double quotes--normally part of a mailto line in html-- inside double quotes of javascript text. <br />
<br />
document.write("<a href='http://www.htmlforums.com/archive/index.php/mailto:" + name + "@" + domain + "." + suffix +"'>")<!--content-->try changing the:<br />
<br />
document.write("<a href='http://www.htmlforums.com/archive/index.php/mailto:" + name + "@" + domain + "." + suffix +"'>")<br />
<br />
to:<br />
<br />
document.write("<a href=http://www.htmlforums.com/archive/index.php/\"mailto:" + name + "@" + domain + "." + suffix +"\">")<br />
<br />
<br />
if you escape the double quotation marks on the javascript .write line then javascript will turn the escape sequence ( \" ) into the regular double quotation mark ( " ) when it writes the information to the doucment...<!--content-->Thanks ucm that takes care of the quotation mark issue, but I still get the error. It's my only error, and if I can fix this it validates! <br />
<br />
Side note related to characters in javascript I found on the W3C javascript tutorial site (but it still makes sense to use ascii codes): <br />
<br />
Insert Special Characters<br />
You can insert special characters (like " ' ; & ) with the backslash:<br />
<br />
document.write ("You \& I sing \"Happy Birthday\".") <br />
<br />
The example above will produce this output:<br />
<br />
You & I sing "Happy Birthday".<!--content-->Hmmm, I have posted this answer 22 times in the last year:<br />
<br />
Hide any closing tags like '</td>' that are within document.write statements by either breaking them open '</' + 'td>' or by escaping them <\/td> and the validator will no longer complain about these closing tags. It is important to break directly after the / and not the middle of a word.<!--content-->Thank you, giz. :(I'm sorry; I always do a search first and this time I didn't bother<br />
<br />
Cool; now my page validates!! :)<!--content-->
 
Back
Top