It doesn't render correctly in any browser I tried.
The point is: this is not the way to do it.
As Eric said, if you can make this determination on the server, it should be handled there. If not, then you can add the attribute under script control on the client, but not with embedded script tags or document.write().
Using jQuery, it'd be as easy as:
Without jQuery, you'd use the native setAttribute() method.