Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Display message new page

    javascript2.js

    Code:
    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?

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by bradz1993 View Post
    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/...th-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.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •