PDA

View Full Version : Error with One function calling another function


vincentms
04-17-2003, 09:25 AM
Hi All,

I dont know why my little code is getting an error. Please take a look and advise.

When I press the nextQuestion button it gets and error. ????

Kind regards,
Vincent




<HTML>
<HEAD>
<SCRIPT>
var r = 0;
var S = 0;
var p = 1;
var tpq = 5;
function getRandom() {
s = Math.round((p - 0.5) + (((tpq + 0.49999) - (p- 0.5)) * Math.random()));
nextQuestion();
return (r);
}
function nextQuestion() {
document.write('<p><input type="radio" value="a" name="q10"> Senegal<br></p>') ;
document.write('<p><input type="radio" value="b" name="q10">' + " " + s + '</span></<br></p>') ;
document.write('<p><input type="radio" value="c" name="q10"> Nigeria<br></p>') ;
document.write('<p><input type="radio" value="d" name="q10"> Mozambique<br></p>') ;
document.write('<INPUT type="button" value="Next Question" onClick=" getRandom()"> ');
return (r);
}

</SCRIPT>
</HEAD>

<BODY>
<FORM name="QForm">
<INPUT type="button" value="Start EXAM"
onClick=" getRandom()">
</FORM>
</BODY>
</HTML>
:confused:

david7777
04-17-2003, 01:05 PM
I think the reason is that when you click the button for the next question, the javascript tries to rewrite the html page completely, and only writes out what is in the "document.write()", leaving out the script code...

So to overcome this, you need to put the questions and the button in spans or divs, and change the contents of those.

I cant remember exactly how, but let me know if you need help and ill find out...

vincentms
04-17-2003, 01:15 PM
Howzit Dave,

You are spot on!!!

I have solved that one in the last few moments, thanks for the reply.

I just returned from 4 weeks in Jo'berg, nice place to visit.

Thanks again,
Vincent