var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength;
function selectAnswerType(){
var selectBox = document.getElementById("questionType");
if (selectBox.value != undefined && selectBox.value != "") {
qType = selectBox.value;
}
else {
return;
}
removeWrongAnswerFields(selectBox);
switch (qType) {
case "int":
selectIntType();
break;
case "scale":
selectScaleType();
break;
case "choice":
//selectChoiceType();
break;
case "text":
//selectTextType();
break;
default:
alert("Invalid answer type selected!");
break;
}
}
function createNewElement(tag, type, id, cl, value) {
var newElement = document.createElement(tag);
if (type != undefined) newElement.type = type;
if (id != undefined) newElement.id = id;
if (cl != undefined) newElement.className = cl;
if (value != undefined) newElement.value = value;
return newElement;
}
function removeWrongAnswerFields(el) {
while (el.nextSibling) {
el.parentNode.removeChild(el.nextSibling);
}
}
function selectIntType() {
var selectBox = document.getElementById("questionType");
var content = document.getElementById("questionEditor_questionParams");
var minValueBox = createNewElement("input","text","minValueBox", "questionParamField", null);
content.innerHTML += "
Min value: ";
content.appendChild(minValueBox);
var maxValueBox = createNewElement("input", "text", "maxValueBox", "questionParamField", null);
content.innerHTML += "
Max value: ";
content.appendChild(maxValueBox);
// set the selected value, because adding a DOM element to the parent element resets the selected value.
for (var i = 0; i < selectBox.options.length; i++) {
if (selectBox.options[i].value == "int") {
selectBox.selectedValue = i;
selectBox.selectedText = "Integer";
// DIT WERKT NOG NIET, HIJ SELECTEERT HEM NIET, OOK AL IS SELECTED = TRUE
// MET ANDERE WOORDEN: WTF.
}
}
}
function selectScaleType() {
debugger;
var selectBox = document.getElementById("questionType");
var content = document.getElementById("questionEditor_questionParams");
var numChoicesBox = createNewElement("select", null, "numChoicesBox","questionParamField",null);
content.innerHTML += "
Scale size: ";
for (var i = 0; i < 10; i++) {
var option = createNewElement("option");
option.text = i+1;
option.value = i+1;
numChoicesBox.appendChild(option);
}
content.appendChild(numChoicesBox);
numChoicesBox.addEventListener("change", selectScaleSize, false);
}
function selectScaleSize() {
var numChoicesBox = document.getElementById("numChoicesBox");
var content = document.getElementById("questionEditor_questionParams");
for (var i = 0; i < numChoicesBox.value; i++) {
var newBullet = createNewElement("input", "radio", "bullet"+i, "questionParamField","i");
content.appendChild(newBullet);
}
}