Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript random title generator

Status
Not open for further replies.

WRATHofGOD18

Programmer
Jul 15, 2003
1
US
Trying to get a random <title> generator going.
Here is what I have:
<title>Title change</title>
<script language=&quot;JavaScript&quot;>

mytitle=new Array()
mytitle[0]=&quot;New Title One&quot;
mytitle[1]=&quot;New Title Two&quot;
mytitle[2]=&quot;New Title Three&quot;
mytitle[3]=&quot;blah&quot;
len=mytitle.length
randnm=Math.round(Math.random()*(len-1))
document.title=mytitle[randnm]
</script>
</head>
<body>
This is a test
</body>
</html>

My question is- can I call a different file (say titles.php) that has all of the titles in it- instead of putting all of the titles in the index.php and having them availible in the source for everyone to see them all?

I have been trying this:
<?PHP
include(&quot;/scripts/titles.php&quot;);
?>

..code

<script language=&quot;JavaScript&quot;>
len=mytitle.length
randnm=Math.round(Math.random()*(len-1))
document.title=titles.mytitle[randnm]
</script>

with titles.php having this in it:
<script language=&quot;JavaScript&quot;>
mytitle=new Array()
mytitle[0]=&quot;New Title One&quot;
mytitle[1]=&quot;New Title Two&quot;
mytitle[2]=&quot;New Title Three&quot;
mytitle[3]=&quot;blah&quot;
</script>

Am I going about this wrong?

Thanks
Jesse
 
Why use a separate php file? Just put your function in a Javascript js file and then in your page put...

<script language=&quot;JavaScript&quot; src=&quot;somefile.js&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top