MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/sb_web/b1536/advancedfunctions.co/combinedScience/
File Upload :
Current < : /hermes/sb_web/b1536/advancedfunctions.co/combinedScience/test.js

//To use, insert <script src="test.js"></script> in HTML file to call this library

//appends a '?' and parameter to URL
function writeParameterToURL(parameter){
location.replace(getURLWithoutParameter()+"?"+parameter);
}

//returns the URL without the parameter
function getURLWithoutParameter(){
return window.location.protocol+"//"+window.location.hostname+window.location.pathname;
}

//writes some 'text' to the element with the 'id' provided
function setText(id, text){
document.getElementById(id).innerHTML=text;
document.getElementById(id).value=text;
}

//returns parameter from URL
function getParameterFromURL(){
    if(window.location.href.indexOf("?")!=-1){
        return window.location.href.replace(getURLWithoutParameter()+"?","");
    }
    else{
        return "";
    }
}

function goToURL(text){
location.replace(text);
}

function makeMCTest(numberOfQuestions,componentID){
var mCTestScript="";
for(var i=0;i<numberOfQuestions;i++){
if(i%2==0){
mCTestScript=mCTestScript+"<h2><div class=''><span><span class='label label-default'>"+(i+1)+"</span></span>&nbsp;<div class='btn-group'><button type='button' class='btn btn-primary' onClick='mCChoice(0"+","+i+")'>A</button></div> <button type='button' class='btn btn-primary' onClick='mCChoice(1"+","+i+")'>B</button> <button type='button' class='btn btn-primary' onClick='mCChoice(2"+","+i+")'>C</button> <button type='button' class='btn btn-primary' onClick='mCChoice(3"+","+i+")'>D</button> <span class='badge'><span id='q"+i+"'></span></span></div></div></h2>";}else{
mCTestScript=mCTestScript+"<h2><div class=''><span><span  class='label label-default'>"+(i+1)+"</span></span>&nbsp;<div class='btn-group'><button type='button' class='btn btn-info' onClick='mCChoice(0"+","+i+")'>A</button></div>  <button type='button' class='btn btn-info' onClick='mCChoice(1"+","+i+")'>B</button> <button type='button' class='btn btn-info' onClick='mCChoice(2"+","+i+")'>C</button> <button type='button' class='btn btn-info' onClick='mCChoice(3"+","+i+")'>D</button> <span class='badge'><span id='q"+i+"'></span></span></div></div></h2>";
}

}
setText(componentID,mCTestScript);
}

function mCChoice(choice, questionNumber){
var choiceLetter=["A","B","C","D"];
setText("q"+questionNumber,choiceLetter[choice]);
return choiceLetter[choice];
}

function getMCAnswersArray(numberOfQuestions){
var answers=new Array();
var answersValid=true;
for(var i=0;i<numberOfQuestions;i++){
answers[i]=getText("q"+i);

if(!(answers [i]=="A"||
answers [i]=="B"||
answers [i]=="C"||
answers [i]=="D")){
response="Invalid Response(s)";
answers[i]="??";
setText("q"+i,answers[i]);
answersValid=false;
}

}
if(!answersValid){return "invalid";}else{
return answers;}
}

function getText(componentId){
return document.getElementById(componentId).innerHTML||document.getElementById(componentId).value;
}

function post(website,data){
jQuery.post(website,data,function(data){
postResults(data);
});
}

function showMCCorrections(corrections,numberOfQuestions,componentId){
var returnDataArray=new Array();
returnDataArray=(corrections.toString()).split(",");

for(var i=1;i<parseInt(numberOfQuestions)+1;i++){
setText("q"+(i-1),returnDataArray[i]);
setText(componentId,"q"+(i-1)+", "+i);
}
setText(componentId,returnDataArray[0]);
}