Java Scripting Random Page To Show

windows

Guest
I am making a Academic test in Dreamweaver for use for a faculty intranet site and using Java to help come up with the page. I am creating different pages each containing a different question. There are 6 sections to the test and I would like one question from each section to be picked randomly for the test so that there are only 6 questions on the test and no one will have the same questions on the test. I brand new to Java and got handed this project with no prior experiance. Here is what I have right now scripting wise.<br />
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br />
<html><br />
<head><br />
<title>Intellectual Copyright</title><br />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br />
<meta http-equiv="refresh" content="5"><br />
</head><br />
<br />
<body><br />
<p> <br />
<script language="JavaScript"><br />
var link1[1]= <a herf="test/first.htm">;<br />
var link2[2]= <a herf="test/second.htm">;<br />
<br />
var r=Math.floor(Math.random()*max);<br />
var c=r+l; <br />
</script><br />
</a><br />
</body><br />
</html><!--content--><!doctype html <br />
public "-//W3C//DTD XHTML 1.0 Transitional//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><br />
<head><br />
<title> new document </title><br />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><br />
<meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT"/><br />
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate"/><br />
<meta http-equiv="Cache-Control" content="post-check=0, pre-check=0"/><br />
<meta http-equiv="Pragma" content="no-cache" /><br />
<br />
<script type="text/javascript"><br />
//<![CDATA[<br />
<br />
q=Array();<br />
<br />
function question(str){<br />
q[q.length]=str;<br />
}<br />
<br />
question("What is the price of tea in China?");<br />
question("What is the weight of gold in Europe?");<br />
question("What is the color of the sky?");<br />
question("Who sells sea shells?");<br />
question("How old is your mom?");<br />
question("Are these questions stupid?");<br />
<br />
//]]><br />
</script><br />
</head><br />
<br />
<body><br />
<script type="text/javascript"><br />
//<![CDATA[<br />
<br />
var r=Math.floor(Math.random()*q.length);<br />
document.write(q[r])<br />
<br />
//]]><br />
</script><br />
<br />
</body><br />
</html><!--content-->I am confused Craig. What do you mean by all of that?<!--content-->You are trying to arbitrarily display a link, correct? Is this easier for you to understand:<br />
<br />
<br />
<!doctype html <br />
public "-//W3C//DTD XHTML 1.0 Transitional//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html><br />
<head><br />
<title> new document </title><br />
</head><br />
<br />
<body><br />
<script type="text/javascript"><br />
//<![CDATA[<br />
<br />
q=Array();<br />
<br />
function question(str){<br />
q[q.length]=str;<br />
}<br />
<br />
question("What is the price of tea in China?");<br />
question("What is the weight of gold in Europe?");<br />
question("What is the color of the sky?");<br />
question("Who sells sea shells?");<br />
question("How old is your mom?");<br />
question("Are these questions stupid?");<br />
<br />
var r=Math.floor(Math.random()*q.length);<br />
document.write(q[r])<br />
<br />
//]]><br />
</script><br />
<br />
</body><br />
</html><!--content-->Well ok that is similar to what I want to do. I am trying to display a page randomly? The code that you have given me just displays the text of the link. How would I show a different page at random?<!--content-->Ah ha!<br />
<br />
<br />
<!doctype html <br />
public "-//W3C//DTD XHTML 1.0 Transitional//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html><br />
<head><br />
<title> new document </title><br />
</head><br />
<br />
<body><br />
<script type="text/javascript"><br />
//<![CDATA[<br />
<br />
p=Array();<br />
<br />
function page(str){<br />
p[p.length]=str;<br />
}<br />
<br />
page("page1.html");<br />
page("page2.html");<br />
page("page3.html");<br />
page("page4.html");<br />
page("page5.html");<br />
page("page6.html");<br />
<br />
var r=Math.floor(Math.random()*p.length);<br />
document.location.replace(p[r])<br />
<br />
//]]><br />
</script><br />
<br />
</body><br />
</html><!--content-->Alright, Now my next question is this. The pages that I want displayed are stored on my computer right now and I am just wanting to test the academic test first before I do anything with it. What would I put where it says:<br />
<br />
page1.html<br />
page2.html <br />
<br />
and the places like that. <br />
<br />
Thank you so much for my help.<!--content-->You would pust the names of the HTML files to load.<!--content-->Ok now when I put this is<br />
<br />
page1(first.html)<br />
page2(second.html)<br />
<br />
and I try to preview in IE all it does it open a new IE window and then closes it right away. Do I also need to put the location of the files into the code where first.html and second.html. I mean put the location of those files into it.<!--content-->You are messing up the syntax. You need to keep the quotes and the syntax. "page" is a function call; you cannot rename it. The values "first.html","second.html" and so on are text strings that you are passing the the "page" function. All it does is create an array of your pages in an easy fashion.<br />
<br />
page("first.html")<br />
page("second.html")<br />
<br />
Just replace the values in each of the function calls with the URL location of the pages to open for each question.<!--content-->Ok so with what I am doing I will need to post the test pages on a server and then use the URL's that are for those pages and post them into the the code right?<!--content-->Thank you so much Craig for your time. This will work out great. If I have anyother problems I will let you know.<!--content-->Ok now I have a link thats titled "Take Test" to a blank page with the Java script in the body of the page and it isn't linking to a random page that I have it linked too. What am I doing wrong is there an easier way then putting into a blank page or when you click on a link can you have a random page show up? I had this working earlier and didn't change anything from the script that you have given me accept the URL's.<!--content-->Forget that last reply. Out of pure ignorance I had a link wrong. I got it solved.<!--content-->
 
Back
Top