⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsquestion.php

📁 调查问卷系统源码。想下的就下吧。不要条件
💻 PHP
📖 第 1 页 / 共 2 页
字号:
				document.addquestion.answeroptions.length++;
				optionsize = document.addquestion.answeroptions.length - 1;
				document.addquestion.answeroptions.options[optionsize].value = temparray[1];
				document.addquestion.answeroptions.options[optionsize].text = temparray[2];
				checkboxarray.length++;
				if (temparray[3] == "D" &&
					((!defaultchecked && (type == "radio" || type == "select")) ||
					(type == "checkbox" || type == "selectmult"))) {
					checkboxarray[checkboxarray.length-1] = true;
					defaultchecked = true;
				} else {
					checkboxarray[checkboxarray.length-1] = false;
				}
				checkboxarray2.length++;
				checkboxarray2[checkboxarray2.length-1] = (temparray[4] == "Y") ? true : false;
			} else if (document.addquestion.others && temparray[2] == "other+") {
				document.addquestion.others.checked = true;
			}
		}
	}
}

function CheckAnswer(answer) {
	if (answer.lastIndexOf("||") >= 0) {
		var tempanswer = answer.split("|||");
		var valid = true;
		for (i=0; i<tempanswer.length; i++) {
			tempanswer2 = tempanswer[i].split("||");
			if (tempanswer2.length != 5) { valid = false; }
		}
		if (valid) { return true; }
	}
	return false;
}

function ClearFieldW (numb) {
	// When focusing on the textfield for the first time, it'll clear it

	if (!fieldinit && document.addquestion.newanswer.value == "Add answer choices here.") {
		document.addquestion.newanswer.value = "";
		fieldinit = true;
	}

	// Clearfield called internally

	if (numb == 1) {
		document.addquestion.newanswer.value = "";
		document.addquestion.dselect.checked = false;
		if (document.addquestion.selectable) {
			document.addquestion.selectable.checked = true;
		}
		fieldinit = true;

		BlurAnswerOptions();
	}
}

function BlurAnswerOptions () {
	document.addquestion.answeroptions.selectedIndex = -1;
}

function FindTextfield () {
	var optionsize = document.addquestion.answeroptions.length;
	var found = false;
	for (i=0; i<optionsize; i++) {
		choice = document.addquestion.answeroptions.options[i].text;
		if (choice.indexOf("Textfield:(") == 0) {
			found = true;
		}
	}
	return found;
}

function AddAnswer (textfield) {
	var tindex = document.addquestion.type.selectedIndex;
	var type = document.addquestion.type.options[tindex].value;
	var answer = document.addquestion.newanswer.value;

	if (answer) {
		if (textfield && (type == "radio" || type == "checkbox" ||
			(type == "select" && !FindTextfield()) || (type == "selectmult" && !FindTextfield()))) {
			answer = "Textfield:("+answer+")";
		} else if ((type == "select" || type == "selectmult") && FindTextfield() && textfield) {
			alert("%%OneTextfieldType%%");
			answer = "";
		}
		if (!textfield && answer.indexOf("Textfield:(") == 0) {
			alert("%%OneTextfieldType%%");
			answer = "";
		}
	}

	if (answer) {
		document.addquestion.answeroptions.length++;
		var cindex = document.addquestion.answeroptions.length - 1;
		document.addquestion.answeroptions.options[cindex].value = 1 + parseInt(largestid);
		document.addquestion.answeroptions.options[cindex].text = answer;
		largestid = parseInt(largestid) + 1;

		// Making sure only one default is chosen for types "radio" and "select"

		if (document.addquestion.dselect.checked && (type == "radio" || type == "select")) {
			for (i=0; i<checkboxarray.length; i++) {
				checkboxarray[i] = false;
			}
		}
		checkboxarray.length++;
		checkboxarray[checkboxarray.length-1] = document.addquestion.dselect.checked;

		// Setting an option to be selectable if selectable option exists

		checkboxarray2.length++;
		if (document.addquestion.selectable) {
			checkboxarray2[checkboxarray2.length-1] = document.addquestion.selectable.checked;
		} else {
			checkboxarray2[checkboxarray2.length-1] = true;
		}

		BlurAnswerOptions();

		ClearFieldW(1);
	}
}

function DeleteAnswer () {
	var cindex = document.addquestion.answeroptions.selectedIndex;
	var deleteanswer = true;

	if (cindex >= 0) {
		// Asking user to confirm deletion for the first time
		if (!deleteinit) {
			deleteanswer = confirm("%%AnswerDeleteWarning%%");
			deleteinit = true;
		}
		if (deleteanswer) {
			var cvalue = document.addquestion.answeroptions.options[cindex].text;
			var optionsize = document.addquestion.answeroptions.length;
			for (i=0; i<optionsize-1; i++) {
				if (i>=cindex) {
					document.addquestion.answeroptions.options[i].text = document.addquestion.answeroptions.options[i+1].text;
					document.addquestion.answeroptions.options[i].value = document.addquestion.answeroptions.options[i+1].value;
					checkboxarray[i] = checkboxarray[i+1];
				}
			}
			document.addquestion.answeroptions.length--;
			checkboxarray.length--;

			BlurAnswerOptions();

			ClearFieldW(1);
		}
	}
	else {
		alert("%%AnswerChoiceDelete%%");
	}
}

function ChangeChoice () {
	var cindex = document.addquestion.answeroptions.selectedIndex;
	var cvalue = document.addquestion.answeroptions.options[cindex].text;

	document.addquestion.newanswer.value = cvalue;
	document.addquestion.dselect.checked = (checkboxarray[cindex]) ? true : false;
	if (document.addquestion.selectable) {
		document.addquestion.selectable.checked = (checkboxarray2[cindex]) ? true : false;
	}
}

function UpdateChoice (whichcheckbox) {
	var tindex = document.addquestion.type.selectedIndex;
	var type = document.addquestion.type.options[tindex].value;
	var cindex = document.addquestion.answeroptions.selectedIndex;
	var ccheck = document.addquestion.dselect.checked;
	if (cindex >= 0) {
		if (type == "radio" || type == "select") {
			if (ccheck) {
				for (i=0; i<document.addquestion.answeroptions.length; i++) {
					checkboxarray[i] = false;
				}
			}
			checkboxarray[cindex] = ccheck;
		} else {
			checkboxarray[cindex] = ccheck;
		}
		if (type == "select" || type == "selectmult") {
			checkboxarray2[cindex] = document.addquestion.selectable.checked;
			if (checkboxarray[cindex] && !checkboxarray2[cindex]) {
				if (whichcheckbox) {
					checkboxarray2[cindex] = true;
					document.addquestion.selectable.checked = true;
					alert("%%SelectedSelectable%%");
				}
				else {
					checkboxarray[cindex] = false;
					document.addquestion.dselect.checked = false;
					alert("%%SelectableSelected%%");
				}
			}
		}
	}
}

function ModifyW () {
	var cindex = document.addquestion.answeroptions.selectedIndex;
	if (cindex >= 0) {
		document.addquestion.answeroptions.options[cindex].text = document.addquestion.newanswer.value;
	}
	else { alert("%%AnswerChoiceModify%%"); }
}

function MoveUpW () {
	var cindex = document.addquestion.answeroptions.selectedIndex;
	if (cindex >= 0) {
		if (cindex != 0) {
			var answertemp = document.addquestion.answeroptions.options[cindex].text;
			var answertemp2 = document.addquestion.answeroptions.options[cindex].value;
			document.addquestion.answeroptions.options[cindex].text = document.addquestion.answeroptions.options[cindex-1].text;
			document.addquestion.answeroptions.options[cindex].value = document.addquestion.answeroptions.options[cindex-1].value;
			document.addquestion.answeroptions.options[cindex-1].text = answertemp;
			document.addquestion.answeroptions.options[cindex-1].value = answertemp2;
			document.addquestion.answeroptions.selectedIndex = cindex-1;

			var checkboxtemp = checkboxarray[cindex];
			checkboxarray[cindex] = checkboxarray[cindex-1];
			checkboxarray[cindex-1] = checkboxtemp;

			var checkboxtemp2 = checkboxarray2[cindex];
			checkboxarray2[cindex] = checkboxarray2[cindex-1];
			checkboxarray2[cindex-1] = checkboxtemp2;
		}
	}
	else { alert("%%AnswerChoiceMove%%"); }
}

function MoveDownW () {
	var cindex = document.addquestion.answeroptions.selectedIndex;
	if (cindex >= 0) {
		if (cindex < document.addquestion.answeroptions.length-1) {
			var answertemp = document.addquestion.answeroptions.options[cindex].text;
			var answertemp2 = document.addquestion.answeroptions.options[cindex].value;
			document.addquestion.answeroptions.options[cindex].text = document.addquestion.answeroptions.options[cindex+1].text;
			document.addquestion.answeroptions.options[cindex].value = document.addquestion.answeroptions.options[cindex+1].value;
			document.addquestion.answeroptions.options[cindex+1].text = answertemp;
			document.addquestion.answeroptions.options[cindex+1].value = answertemp2;
			document.addquestion.answeroptions.selectedIndex = cindex+1;

			var checkboxtemp = checkboxarray[cindex];
			checkboxarray[cindex] = checkboxarray[cindex+1];
			checkboxarray[cindex+1] = checkboxtemp;

			var checkboxtemp2 = checkboxarray2[cindex];
			checkboxarray2[cindex] = checkboxarray2[cindex+1];
			checkboxarray2[cindex+1] = checkboxtemp2;
		}
	}
	else { alert("%%AnswerChoiceMove%%"); }
}

function SaveAnswers () {
	var optionsize = document.addquestion.answeroptions.length;
	var answer = "";
	var zero = "";
	var defaultchoice = "";

	for (i=0; i<optionsize; i++) {
		if (i != 0) {
			answer = answer + "|||";
		}

		zero = "";
		if (i+1 < 10) { zero = zero + "0"; }
		if (i+1 < 100) { zero = zero + "0"; }
		if (i+1 < 1000) { zero = zero + "0"; }

		defaultchoice = (checkboxarray[i]) ? "D" : "N";
		if (document.addquestion.selectable) {
			selectable = (!checkboxarray2[i]) ? "N" : "Y";
		} else {
			selectable = "Y";
		}

		answer = answer + zero + (i+1) + "||";
		answer = answer + document.addquestion.answeroptions.options[i].value + "||";
		answer = answer + document.addquestion.answeroptions.options[i].text + "||";
		answer = answer + defaultchoice + "||";
		answer = answer + selectable;

	}

	document.addquestion.answer.value = answer;
}

// The following code allows the user to simply hit the enter key 
// when adding answers to speed up the process.
var nav = window.Event ? true : false;
if (nav) {
	 window.captureEvents(Event.KEYDOWN);
	 window.onkeydown = NetscapeEventHandler_KeyDown;
} else {
	 document.onkeydown = MicrosoftEventHandler_KeyDown;
}

function NetscapeEventHandler_KeyDown(e) {
	if (e.which == 13 && e.target.name == 'newanswer') { AddAnswer(false); return false; }
	return true;
}

function MicrosoftEventHandler_KeyDown() {
	if (event.keyCode == 13 && event.srcElement.name == 'newanswer') {
		AddAnswer(false);
		return false;
	}
	return true;
}

</SCRIPT>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -