PDA

View Full Version : document.write PROBLEMS



c1hundred
04-14-2009, 08:57 AM
Hi, I'm new on forum.

Anyway, I have this code but it doesn't work.
If I remove the CSS in the document.write function it works fine.
I have tried moving background:url(); to background='' in the anchor but that still doesn't work.


function generate(){

var user = document.getElementById('user').value;

document.write("<style type='text/css'>
.subscribe {
font-family:Arial;
background:url(subscribe.png) no-repeat;
font-weight:bold;
width:80px;
height:25px;
padding:5px 12px 5px 8px;
color:#994800;
text-decoration:none;
}
.subscribe:hover {
text-decoration:underline;
}
</style>
<a href='http://youtube.com/subscription_center?adduser="+ user +"' class='subscribe'>Subscribe</a>");

}

Thanks for any help given!!!

molendijk
04-14-2009, 03:34 PM
If you want to write styles, the code must have the following form:


document.write('<style type="text/css">');
document.write('.subscribe {font-family:comic sans ms;text-decoration:none;background-color:transparent;font-size:11px;}');
document.write('</style>');

Moreover, putting the document.write in a function makes no sense, since applying the function after page load overwrites everything on the page.
===
Arie.