0

Hi, im trying to make a quiz in which we can alternate b/w 2 questions for now....The thing im trying to do is that suppose we're on question 1, we answer and proceed to question 2, when i come back to question 1, that answer should be visible in the text box, however, this code is nt giving me any response text, could u please help me out?

im certain the problem is when im calling the saveAnswer(id, readText(this.form)) function in the html...please help!

<html>
<head>
<script type="text/javascript">

	answers = new Array();

function showQuestion(id)
	{	
		
		if(id == "" || id == null)
		{
			document.getElementById("question").innerHTML = "Please select the question";
			return;
		}
		else
			var answerHTML = "<form id='test' onSubmit='return false;'><input type='text' name='qans' value='" + displaySavedAnswer(id) + "'><button type='button' name='submit' onClick='"+saveAnswer(id, readText(this.form))+"'>Save Answer</button></form>";
			
		if(window.XMLHttpRequest)
			xmlhttp = new XMLHttpRequest();
		else
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			
		xmlhttp.onreadystatechange = function()
			{
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
					{
						document.getElementById("question").innerHTML = xmlhttp.responseText;
						document.getElementById("answer").innerHTML = answerHTML;
					}
			}
			
		xmlhttp.open("GET", "process.php?id="+id, true);
		xmlhttp.send();	
			
	}	
	
function saveAnswer(id, form)
	{		
		var answer = form.qans.value;
		answers[id] = answer;
	}
	
function displaySavedAnswer(id)
	{
		return answers[id];
	}


</script>
</head>
<body>

<form action="">
<select name="qid" onchange="showQuestion(this.value)">
<option value="">Select a Question:</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>

<div id="question"></div>
<div id="answer"></div>


</body>
</html>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by pritaeas
0

readText appears to be a function, but where is it defined ? Not sure, but maybe you don't need it.

Edited by pritaeas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.