scripts and thoughts from my work and hobby

Menu

SharePoint Survey – Randomise questions

My last post was about my disappointment in finding out that workflows cannot be used with surveys… I was trying to build a quiz that would display random questions from a pool and then automatically grade the quiz using a workflow. At this point, the grading won’t happen but I thought I’d share my code that I used to randomise the questions in the survey.

The code uses javascript to hide (display: none) the TDs that hold the questions and answers on the NewForm.aspx then display a set number of those Q&As randomly.

I haven’t done extensive testing, but it seems okay. I pasted the below after ‘</WebPartPages:WebPartZone>’ on my survey’s NewForm.aspx.

for(var x = 1; x <= numQs; x++) {
//propose a random number and check if it has been used
do {
proposedQno = Math.ceil(Math.random()*QAsetno);
} while (randQno.inArray(proposedQno)!=false);
//at this point, the proposedQno will be unique so we can add it to the list of used numbers
randQno[x] = proposedQno;

I was hoping I could do something similar (building a auto-graded quiz) using a custom list, but the layout on a list NewForm.aspx seems a lot more complicated for a one-fits-all solution such as this.

Post navigation

5 thoughts on “SharePoint Survey – Randomise questions”

This code is exactly what ive been looking for to solve a problem i have. Unfortunately i am not an expert in javascript so i am unable to get this to work. I have inserted content editor webparts before which have worked. Unfortunately i dont have access to designer either. I just wonder if there are parts in this code that i need to alter before it will work?? So, I have a test survey with 7 questions and i want it to select 4 at random every time someone clicks respond to this survey. Any help would be appreciated

Hi Jonathan, this post is pretty old and was designed to work with MOSS 2007 – I haven’t test on later versions of SharePoint. I’m not an expert, but I think this code must be placed on the NewForm.aspx as it’s own code i.e. not in a content editor web part.

Do i have to change anything in the code above. Please let me know what needs to be changed. Your reply will be appreciated. It will be very helpful for me. I am looking out for the exact requirement. Please…………