...

View Full Version : Display message new page



bradz1993
03-13-2012, 01:34 PM
javascript2.js




function displayMessage(msg) {

// Open a new window
var msgWindow = window.open('', 'Message');

// Write message in the new Window
msgWindow.document.write(msg);

// Raise this window, in case it's not visible
msgWindow.focus();

}

//Enter total number of questions:
var totalquestions=13

var correctchoices=new Array("a","a","b","c","b","c","a","a","b","c","a","b","b");


var correctanswers=new Array("memory locations","_ underscore","x=5+5;","20","Else","lose win","ticker = ticker + 1;","Ticker = ticker + 1;","300.000","Jonathon \b","var","var counter;","var mark = 50, 70");


function gradeit(){
var actualchoices=new Array()
var msg1=new Array()
var correctanswersno=0
var t=0
var displaycorrectanswers=""
for (q=1;q<=totalquestions;q++){
var thequestion=eval("document.Questionform.q"+q)

for (c=0;c<thequestion.length;c++){
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}

if (actualchoices[q]==correctchoices[q]){
msg1[t]=q+")"+" Correct";
correctanswersno = correctanswersno + 1;
t = t + 1;
} else {
msg1[t]=q+")"+" Incorrect: <br>Correct Answer: "+correctchoices[q]+") "+correctanswers[q];
t = t + 1;
}
}

for (p=0;p<=12;p++){
displaycorrectanswers+="<br>"+msg1[p];
}



var msg="Score: "+correctanswersno+"/"+totalquestions+" <br><br>Marks: "+displaycorrectanswers;
displayMessage(msg);

}



Basically on my index page it has a button which when clicked makes use of gradeit(). Currently this then used displayMessage(msg) which opens a new window and displays the message.

However, what I want it to do is to open another created html page e.g. answer.html and then for this page to display the message. How do i do this?

Rowsdower!
03-13-2012, 02:21 PM
Basically on my index page it has a button which when clicked makes use of gradeit(). Currently this then used displayMessage(msg) which opens a new window and displays the message.

However, what I want it to do is to open another created html page e.g. answer.html and then for this page to display the message. How do i do this?

Basic idea would be that you submit the form to answer.html with target="_blank" and method="get" parameters. Then, once you land on the grading page you would have javascript there to read the "get" variables (which would now be part of the URL) and grade the answers accordingly on the window.onload event in order to populate the page with a suitable message based on their performance.

Here is one method of accessing "get" variables with javascript (to be used in answer.html):
http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/

Try to dig in with this a bit and post back if you get stuck so we can see what you've tried so far.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum