One or Several Did You Know Quiz Multiple Tailored Sharing Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

One or Several Did You Know Quiz Multiple Tailored Sharing Tutorial

One or Several Did You Know Quiz Multiple Tailored Sharing Tutorial

Yes, it was the case with yesterdayโ€™s One or Several Did You Know Quiz Multiple Sharing Tutorial that we did not allow any sharing of any question sets that were not our static default ones โ€ฆ

You werenโ€™t dreaming!

At first we could not imagine how to bring across all of the window.localStorage work over via the Inline HTML Email Form method=GET form way to the rjmprogramming.com.au webpage off that and into that sessionโ€™s window.localStorage in time to be able to offer a tailored user defined question as one to be offered via email.

But we were not thinking as clearly as we might. We only need one questionโ€™s worth of data funnelling through that โ€œmethod=GETโ€ (potential) blockage at a time, and we can gradually build up the window.localStorage content of the โ€œToโ€ email recipient to eventually match that of the window.localStorage content of the โ€œhosterโ€ over time, because we now pass across another (optional) mantissa usage concept example โ€ฆ



&question=[questionNumber].[numberOfTailoredQuestionsInQuiz]

&qs=[currentQuestionText]

&os=[currentDisplayAnswerList]

&as=[currentCorrectAnswerList]

โ€ฆ enough information on a scenario where the โ€œToโ€ email recipient having no window.localStorage we just default it to [numberOfTailoredQuestionsInQuiz] sets resulting in โ€ฆ



"[numberOfTailoredQuestionsInQuiz]x,[currentQuestionText]"^"[numberOfTailoredQuestionsInQuiz]x,[currentDisplayAnswerList]"^"[numberOfTailoredQuestionsInQuiz]x,[currentCorrectAnswerList]"

โ€ฆ initially in the โ€œToโ€ emaileeโ€™s window.localStorage and then subsequently updated depending on the next [questionNumber] to come by for ourchanged one_or_several_quizโšซhtmlโ€˜s Oneโœ‚or Several Did You Know Quiz web application, way below as well โ€ฆ



Previous relevant One or Several Did You Know Quiz Multiple Sharing Tutorial is shown below.

One or Several Did You Know Quiz Multiple Sharing Tutorial

One or Several Did You Know Quiz Multiple Sharing Tutorial

The day before yesterdayโ€™s One or Several Did You Know Quiz Multiple Mobile Tutorialโ€˜s One or Several Did You Know Quiz Tailored Quiz Tutorial mentioned โ€ฆ

  • stick with some default static data โ€ฆ or โ€ฆ
  • be able to create their own data which they can recall โ€ฆ and maybe even โ€ฆ
  • go further and share and/or collaborate using that data (or the default data) (where apt)

โ€ฆ where the โ€œand maybe evenโ€ ideas weโ€™re trying to push through today with improvements under a โ€œshare and/or collaborateโ€ umbrella (trying not to get too wet in the process).

So how does our new email โ€œsharingโ€ functionality work?

  1. the โ€œhosterโ€ of email communications clicks an email ๐Ÿ“ง emoji link โ€ฆ
  2. the hoster is asked โ€ฆ


    emailto=prompt("Share your quiz questions with which email address? Optionally semicolon separate your email address ( which can be of the form J.Smith[jsmith@emailclient.com] ) which the recipient sees as the CC recipient.", "");

  3. and if valid email addresses are defined here an Inline HTML Email Form is sent to the โ€œToโ€ email address defined (via our favoured โ€œmidairโ€ Ajax/FormData methodology) โ€ฆ


    function emailit() {

    var zhr = new XMLHttpRequest();

    var zform=new FormData();

    var fromx='youllneverfindthis';

    var tox='youwillneverfindthis';

    zform.append('inline', '');

    if (emailto.indexOf(';') != -1) {

    zform.append('to', emailto.split(';')[0]);

    if (emailto.split(';')[1].indexOf('@') != -1) {

    if (emailto.split(';')[1].indexOf('[') != -1 && emailto.split(';')[1].indexOf(']') != -1) {

    zform.append('cc', emailto.split(';')[1].split(']')[0].split('[')[1]);

    fromx=' Quiz<';

    //tox=' Quiz sent by ' + emailto.split(';')[1].replace('[' + emailto.split(';')[1].split(']')[0].split('[')[1] + ']', '') + '<';

    tox=' Quiz sent by <a target=_blank title=Email href="mailto:' + emailto.split(';')[1].split(']')[0].split('[')[1] + '?subject=Quiz">' + emailto.split(';')[1].replace('[' + emailto.split(';')[1].split(']')[0].split('[')[1] + ']', '') + '</a><';

    } else {

    zform.append('cc', emailto.split(';')[1]);

    }

    } else {

    fromx=' Quiz<';

    //tox=' Quiz sent by ' + emailto.split(';')[1] + '<';

    tox=' Quiz sent by <a target=_blank title=Email href="mailto:' + emailto.split(';')[1] + '?subject=Quiz">' + emailto.split(';')[1] + '</a><';

    }

    } else {

    zform.append('to', emailto);

    }

    zform.append('subj', 'Did You Know Quiz');

    var fromc=document.getElementById('score').innerHTML;

    var toc='Score: ' + document.getElementById('hscore').value + '/' + document.getElementById('hgoes').value;

    if (dbih != '') {

    zform.append('htmlis', '<body>' + dbih.replace('display:NONE','display:BLOCK').replace(/In\ order\ w/g,'W').replace(/In\ order\ /g,'').replace(/\,/g,', ').replace(fromc, toc).replace(fromx, tox).replace('๐Ÿ“ง',',') + '</body>');

    } else {

    zform.append('htmlis', '<body>' + document.body.innerHTML.replace('display:NONE','display:BLOCK').replace(/In\ order\ w/g,'W').replace(/In\ order\ /g,'').replace(/\,/g,', ').replace(fromc, toc).replace(fromx, tox).replace('๐Ÿ“ง',',') + '</body>');

    }

    zhr.open('post', '//www.rjmprogramming.com.au/HTMLCSS/emailhtml.php', true);

    zhr.send(zform);

    return false;

    }

  4. and for the โ€œToโ€ emailee opening that email they fill out an answer set and click the โ€œAm I Correct?โ€ button to navigate back to the public rjmprogramming.com.au domain webpage โ€ฆ where โ€ฆ
  5. scores are updated and then saved in window.localStorage to recall for any more emails that arrive from emails sent by the โ€œhosterโ€ in their session sharing the quiz with the โ€œToโ€ emailee โ€ฆ as well as there being a way for the โ€œToโ€ emailee user venture off on their own quiz in a new web browser tab as required

If this sounds interesting you could try ourchanged one_or_several_quizโšซhtmlโ€˜s Oneโœ‚or Several Did You Know Quiz web application, way below as well โ€ฆ


Previous relevant One or Several Did You Know Quiz Multiple Mobile Tutorial is shown below.

One or Several Did You Know Quiz Multiple Mobile Tutorial

One or Several Did You Know Quiz Multiple Mobile Tutorial

Yesterdayโ€™s One or Several Did You Know Quiz Tailored Quiz Tutorial was accurate regarding its information for non-mobile users but lacked some mobile relevant issue (and discovery) information โ€ฆ

  • the โ€œIn Orderโ€ questions were unfair for mobile users given yesterdayโ€™s Javascript code because the select element option element โ€œonclickโ€ event is not recognized on mobile platforms and so we had a โ€œGoldilocksโ€ solution set to contemplate โ€ฆ
    1. not ask โ€œIn order โ€ฆโ€ questions โ€ฆ too cold
    2. force the dropdown display order to correspond to the answer order โ€ฆ too hot
    3. ask the question without โ€œIn order โ€ prefix and flag answer array member to have โ€œpadded commaโ€ delimitation that tells the program any answer order with the correct data items will score โ€ฆ just right

    โ€ฆ and surprise, surprise, we chose the third approach

  • Are you like me always wishing on mobile platforms that the size attribute would be honoured on dropdown (ie. select) elements? Well, we discovered a kludge we probably had never tried because we thought you could only programmatically focus to input type=text types of elements, but (and what got our interest was a blue focus border on one) select element on mobile platforms can be focussed to via โ€ฆ
    [selectElementObject].focus();
    โ€ฆ which opens up a fair few lines of a select element as if you could see size=4 (for short entries). Cute, huh?!
  • alas, work to put those background colours and numbers after ticks onto those select element option subelements, did not result in progress for us, for mobile platforms

This means you could try ourchanged one_or_several_quizโšซhtmlโ€˜s Oneโœ‚or Several Did You Know Quiz web application, below as well โ€ฆ


Previous relevant One or Several Did You Know Tailored Quiz Tutorial is shown below.

One or Several Did You Know Tailored Quiz Tutorial

One or Several Did You Know Tailored Quiz Tutorial

The word โ€œstaticallyโ€ in yesterdayโ€™s One or Several Did You Know Quiz Multiple Tutorial can have an adverse effect on me. Static โ€œHTMLโ€ is pretty boring, unless the data is something to write home about. Even dynamic HTML powered by static Javascript (for example hard coded array data sets) is still apt to be boring after some time. We fail sometimes, but where we see an opportunity with inhouse web applications we like the user (to be able) to choose between โ€ฆ

  • stick with some default static data โ€ฆ or โ€ฆ
  • be able to create their own data which they can recall โ€ฆ and maybe even โ€ฆ
  • go further and share and/or collaborate using that data (or the default data) (where apt)

โ€ฆ and todayโ€™s work involves that middle choice above, some functionality we like to label โ€œaccountabilityโ€, to our mind. But we hear you say โ€ฆ

But couldnโ€™t the data size get quite large if you open it up to the user deciding on it?

Good point, and fair enough! We could involve PHP and use POST arguments. But (and three buts do not a butte make) weโ€™ve decided this quiz is meant to be pared down, and relatively uncomplicated. Weโ€™re going to stay with just clientside Javascript techniques, but agree we cannot rely on the puny sizes GET arguments allow you to work with. Is there an alternative just in the clientsize wooooooorrrrrrlllllldddd? Yes โ€ฆ

HTTP Cookies

Yes, but is there a more generous one, anyone, anyone? Yes, Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr., thank you for your succinct answer โ€ฆ

window.localStorage

So, in the quiz Javascript, we โ€œaskโ€ โ€ฆ



function ask() {

var cnt=0;

var theq=" ", cdelimq="";

var them=" ", cdelimm="";

var thea=" ", cdelima="";

overallq="";

overallm="";

overalla="";

while (theq != "" && them != "" && thea != "") {

if (qs.length > cnt) {

theq=prompt("Enter question(s) (delimited by |) for set " + eval(1 + cnt), qs[cnt]);

} else {

theq=prompt("Enter question(s) (delimited by |) for set " + eval(1 + cnt), "");

}

if (!theq) { theq=""; }

if (theq != '') {

if (os.length > cnt) {

them=prompt("Enter full list of choices using comma delimitation " + eval(1 + cnt), os[cnt]);

} else {

them=prompt("Enter full list of choices using comma delimitation " + eval(1 + cnt), "");

}

if (!them) { them=""; }

}

if (theq != '' && them != '') {

if (as.length > cnt) {

thea=prompt("Enter full list of correct answer (using padded comma delimitation where order does not matter) set(s) (delimited by |) " + eval(1 + cnt), as[cnt]);

} else {

thea=prompt("Enter full list of correct answer (using padded comma delimitation where order does not matter) set(s) (delimited by |) " + eval(1 + cnt), "");

}

if (!thea) { thea=""; }

}

if (theq != "" && them != "" && thea != "") {

overallq+=cdelimq + '"' + theq + '"';

overallm+=cdelimq + '"' + them + '"';

overalla+=cdelimq + '"' + thea + '"';

cdelimq=",";

cdelimm=",";

cdelima=",";

cnt++;

}

}

if (overallq != "" && overallm != "" && overalla != "") {

//alert(1);

if (window.localStorage) {

//alert(11);

if (('' + window.localStorage.getItem("dykquiz")).replace('undefined','').replace('null','') != '') {

window.localStorage.removeItem("dykquiz");

window.localStorage.setItem("dykquiz", encodeURIComponent(overallq + '^' + overallm + '^' + overalla));

} else {

window.localStorage.setItem("dykquiz", encodeURIComponent(overallq + '^' + overallm + '^' + overalla));

}

}

location.href=document.URL.split('#')[0].split('?')[0];

}

if (document.getElementById('sdyk')) {

document.getElementById('sdyk').value=prevs;

}

}

โ€ฆ and, as necessary, โ€œrecallโ€ โ€ฆ



var overallq="";

var overallm="";

var overalla="";



function getask() {

qs=eval("[" + overallq + "]");

os=eval("[" + overallm + "]");

as=eval("[" + overalla + "]");

pickq();

}



if (window.localStorage) {

if (('' + window.localStorage.getItem("dykquiz")).replace('undefined','').replace('null','') != '') {

var bigqa=decodeURIComponent(window.localStorage.getItem("dykquiz"));

var bqs=bigqa.split('"^"');

if (bqs.length >= 3) {

overallq=bqs[0] + '"';

overallm='"' + bqs[1] + '"';

overalla='"' + bqs[2];

document.getElementById('smode').innerHTML="<select id=sdyk onchange=' if (this.value.length != 0) { eval(this.value); } prevs=this.value; ' style=display:inline-block;><option value=''>" + '"' + "Did You Know" + '"' + "</option><option onclick=getask(); value='getask();'>Recall Saved Quiz Questions and Answers</option><option onclick=ask(); value='ask();'>Reask</option></select>";

}

}

}

โ€ฆ references the changed HTML snippet โ€ฆ



<h1>One or Several <div id=smode style=display:inline-block;><a title='Asks for your question and answer data for quiz' id=dmode style='cursor:pointer;text-decoration:underline;' onclick=ask();>"Did You Know"</a></div> Quiz</h1>

All of which means you could try ourchanged one_or_several_quizโšซhtmlโ€˜s Oneโœ‚or Several Did You Know Quiz web application.


Previous relevant One or Several Did You Know Quiz Multiple Tutorial is shown below.

One or Several Did You Know Quiz Multiple Tutorial

One or Several Did You Know Quiz Multiple Tutorial

Yesterdayโ€™s One or Several Did You Know Quiz Primer Tutorial represented part one of two (so far) โ€œdropdown helps out quizโ€ paradigm. Yesterday was โ€ฆ

  • single question and single answer
  • single question and block of consecutive answers
  • single question and multiple answers in any order
  • single question and multiple answers in a particular order

โ€ฆ and onto that today we want to add โ€ฆ

  • multiple question(s) offered and single answer(s) processed
  • multiple question(s) offered and block(s) of consecutive answers
  • multiple question(s) offered and multiple set(s) of unique answers in any order
  • multiple question(s) offered and multiple set(s) of not necessarily unique answers in any order โ€ฆ for example, the two questions below are the innerText of one of our quiz questions โ€ฆ


    Which countries comprise Indochina?

    Which countries border the Gulf of Thailand?

    โ€ฆ a concept we cater for via delimiter โ€œ|โ€ โ€ฆ


    Which countries comprise Indochina?|Which countries border the Gulf of Thailand?


    โ€ฆ usage in our, so far, statically created Javascript arrays that represent our quizโ€™s โ€œdata arrangementsโ€
  • multiple question(s) offered and multiple set(s) of answers in a particular order

โ€ฆ that fourth new possibility having us interested in โ€ฆ

  • select element โ€ฆ
  • multiple attribute โ€ฆ
  • option subelement โ€œonclickโ€ event logic โ€ฆ
  • now allowing for option click repeats if the answers have repeated data items (which only happens if multiple questions are selected) โ€ฆ


    function oneanswer(invlo) {

    var invl=invlo.value + '|', adone=false;

    if (invl == '') { return ''; }

    inthegame=true;

    var isvalid=false;

    var morethanone=0;

    document.body.style.cursor='pointer';

    if (('' + invl).indexOf('|') != -1) {

    if ((',' + gmlist.replace(/\ /g,'') + ',').indexOf(',' + invl.split('|')[0].replace(/\ /g,'') + ',') == -1) {

    isvalid=true;

    if (gmlist == '') {

    gmlist=invl.split('|')[0];

    } else {

    gmlist+=',' + invl.split('|')[0];

    }

    } else if (repeated) {

    //alert('gmlist=' + gmlist);

    isvalid=true;

    gmlist+=',' + invl.split('|')[0];

    }

    // alert('gmlist=' + gmlist);

    }



    var sin=document.getElementById('answer');

    for (var ii=1; ii<sin.options.length; ii++) {

    if (sin.options[ii].selected) {

    morethanone++;

    }

    }




    if (morethanone > 1) {

    gmlist='';

    isvalid=false;

    }




    for (var i=1; i<sin.options.length; i++) {

    if (sin.options[i].selected) {

    if (sin.options[i].innerText.indexOf(String.fromCodePoint(10004)) == -1) {

    sin.options[i].innerText+=' ' + String.fromCodePoint(10004);

    //alert(1);

    } else if (morethanone > 1) {

    adone=false;

    if (sin.options[i].innerText.split(String.fromCodePoint(10004)).length > 1) {

    if (sin.options[i].innerText.split(String.fromCodePoint(10004))[1].trim() != '') {

    adone=true;

    }

    }

    if (!adone) { sin.options[i].innerText=sin.options[i].innerText.split(String.fromCodePoint(10004))[0] + String.fromCodePoint(10004); }

    }

    if ((sin.options[i].value + '|').indexOf('|') != -1) {

    //if (gmlist.indexOf((sin.options[i].value + '|').split('|')[0]) == -1) {

    if ((',' + gmlist.replace(/\ /g,'') + ',').indexOf(',' + (sin.options[i].value + '|').split('|')[0].replace(/\ /g,'') + ',') == -1) {

    if (gmlist == '') {

    gmlist=(sin.options[i].value + '|').split('|')[0];

    } else {

    gmlist+=',' + (sin.options[i].value + '|').split('|')[0];

    }

    if ((sin.options[i].innerText + ' ').indexOf(' ' + gmlist.split(',').length + ' ') == -1) {

    sin.options[i].innerText+=' ' + gmlist.split(',').length;

    }

    //alert(3);

    }

    } else {

    adone=false;

    if (sin.options[i].innerText.split(String.fromCodePoint(10004)).length > 1) {

    if (sin.options[i].innerText.split(String.fromCodePoint(10004))[1].trim() != '') {

    adone=true;

    }

    }

    //alert('adone=' + adone);

    }

    } else if (morethanone > 1) {

    if (sin.options[i].innerText.indexOf(String.fromCodePoint(10004)) != -1) {

    sin.options[i].innerText=sin.options[i].innerText.split(String.fromCodePoint(10004))[0];

    //alert(2);

    sin.options[i].style.backgroundColor='white';

    //} else {

    //alert(7);

    }

    } else if (invl.indexOf(sin.options[i].value) == 0) {

    adone=false;

    if (sin.options[i].innerText.split(String.fromCodePoint(10004)).length > 1) {

    if (sin.options[i].innerText.split(String.fromCodePoint(10004))[1].trim() != '') {

    adone=true;

    }

    }

    //alert('5:' + morethanone + ':' + invl + ' adone=' + adone + ' gmlist=' + gmlist);

    }

    }



    if (isvalid) {

    invlo.style.backgroundColor='rgb(230,230,230)';

    if ((invlo.innerText + ' ').indexOf(' ' + gmlist.split(',').length + ' ') == -1) {

    invlo.innerText+=' ' + gmlist.split(',').length;

    }

    validcall=false;

    if (morethanone == 1) {

    //alert(8);

    document.body.style.cursor='progress';

    setTimeout(scoreit, 15000);

    } else {

    //alert(9);

    scoreit();

    }

    } else {

    //alert(0);

    document.body.style.cursor='progress';

    setTimeout(scoreit, 15000);

    }

    }

And so you could try ourchanged one_or_several_quizโšซhtmlโ€˜s Oneโœ‚or Several Did You Know Quiz web application, below as well โ€ฆ


Previous relevant One or Several Did You Know Quiz Primer Tutorial is shown below.

One or Several Did You Know Quiz Primer Tutorial

One or Several Did You Know Quiz Primer Tutorial

The inspiration for todayโ€™s โ€œOne or Several Did You Know Quizโ€ web application came from yesterdayโ€™s YouTube Embedded Iframe API Summary Singular Multiple Dropdown Tutorial select elementโ€™s option subelementโ€™s onclick event logic whereby we turn the โ€œmultipleโ€ attribute on for the dropdown, and work the logic so that all of โ€ฆ

  • single question and single answer
  • single question and block of consecutive answers
  • single question and multiple answers in any order
  • single question and multiple answers in a particular order

โ€ฆ quiz answer modi operandi are catered for. Even for todayโ€™s quiz scenario โ€ฆ

  • swap the need for an accompanying button next to a select โ€œmultipleโ€ attribute dropdown โ€ฆ with โ€ฆ
  • select (dropdown) element option subelement set of โ€œonclickโ€ logic call event logics linked with setTimeout delay methodologies

This means we can have a quiz with a โ€œpotpourriโ€ feel to it with questions that can have answers that are โ€ฆ

  • single answer โ€ฆ single question and single answer
  • block of consecutive answers (suits select โ€œmultipleโ€ shift key usage) โ€ฆ single question and block of consecutive answers
  • single or โ€œcommand or ctrl keyโ€ option clicks (where order can be a part of the analysis) โ€ฆ single question and multiple answers in any order and single question and multiple answers in a particular order

โ€ฆ meaning your quiz can be quite interesting, perhaps a little whacky, for your users.

Hereโ€™s that select element option subelement event quiz logic (as a result of the โ€œinspirationโ€ mentioned above) โ€ฆ



function oneanswer(invlo) {

var invl=invlo.value + '|';

if (invl == '') { return ''; }

inthegame=true;

var isvalid=false;

var morethanone=0;

if (('' + invl).indexOf('|') != -1) {

if (gmlist.indexOf(invl.split('|')[0]) == -1) {

isvalid=true;

if (gmlist == '') {

gmlist=invl.split('|')[0];

} else {

gmlist+=',' + invl.split('|')[0];

}

}

// alert('gmlist=' + gmlist);

}



var sin=document.getElementById('answer');

for (var ii=1; ii<sin.options.length; ii++) {

if (sin.options[ii].selected) {

morethanone++;

}

}




if (morethanone > 1) {

gmlist='';

isvalid=false;

}




for (var i=1; i<sin.options.length; i++) {

if (sin.options[i].selected) {

if (sin.options[i].innerText.indexOf(String.fromCodePoint(10004)) == -1) {

sin.options[i].innerText+=' ' + String.fromCodePoint(10004);

} else if (morethanone > 1) {

sin.options[i].innerText=sin.options[i].innerText.split(String.fromCodePoint(10004))[0] + String.fromCodePoint(10004);

}

if ((sin.options[i].value + '|').indexOf('|') != -1) {

if (gmlist.indexOf((sin.options[i].value + '|').split('|')[0]) == -1) {

if (gmlist == '') {

gmlist=(sin.options[i].value + '|').split('|')[0];

} else {

gmlist+=',' + (sin.options[i].value + '|').split('|')[0];

}

sin.options[i].innerText+=' ' + gmlist.split(',').length;

}

}

} else if (morethanone > 1) {

if (sin.options[i].innerText.indexOf(String.fromCodePoint(10004)) != -1) {

sin.options[i].innerText=sin.options[i].innerText.split(String.fromCodePoint(10004))[0];

sin.options[i].style.backgroundColor='white';

}

}

}



if (isvalid) {

invlo.style.backgroundColor='rgb(230,230,230)';

invlo.innerText+=' ' + gmlist.split(',').length;

validcall=false;

if (morethanone == 1) {

setTimeout(scoreit, 9000);

} else {

scoreit();

}

} else {

setTimeout(scoreit, 9000);

}

}

So try our one_or_several_quizโšซhtmlโ€˜s Oneโœ‚or Several Did You Know Quiz web application, below as well โ€ฆ

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in Ajax, eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *