Hello there, I need my page to randomly select a CSS document. I don't want the user to select it, but instead to do it when the page loads.
This is the script I have so far:

<script language="javascript" type="text/javascript">
	var ranNum= Math.floor(Math.random()*3+1); 
	document.write("<link rel='stylesheet' href='hd"+ranNum+".css' type='text/css'>"); 
</script>

This function does write the proper <style> tag, but it does not work. :evil: When I go to "view source", I don't see the line that suppously was written by the JS function.

PLEASE HELP!!:-|

The "document.write" statement is deprecated in most new doctypes.

However, with a loose (or no) doctype, this should work. Where is the script running? It needs to run in the <HEAD> section of your page.

Give us a link?

When I go to "view source", I don't see the line that suppously was written by the JS function.

You don't usually get to see the line that was written, since it happens on the client. The "view source" option gives you the original source, not the client-execution result.

I need my page to randomly select a CSS document. I don't want the user to select it, but instead to do it when the page loads.

Is that mean skin chooser? For user selects the CSS style and reload the page.

Me again, sorry for the late response, it was the weekend.
I don't want the user to select the a CSS and then refresh the page. I want to do that for them.

The way I have setup my page is that I have one CSS for the whole page: styles.CSS, and then I have 3 other CSS documents (hd1.css, hd2.css, hd3.css) that I want to use them in the document randomly.

Here is the page
http://www.arch.usyd.edu.au/~jrui0688/template.htm

(this is the testing page).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.