use javascript to create test checker

upsellasegree

New Member
I am a maths teacher. I want to use my school's website to allow pupils to check whether they have the correct solutions to a set of test questions given separately on paper. I wanted to give pupils a textbox in which they can enter their solution and a button to press to check if it is correct. A correct answer will display a 'correct' icon next to the question etc. I am a complete beginner but I have so far managed:\[code\]<script>function check(z){var ans = new Arrayans[0]="522"ans[1]="144"if (document.getElementById('response'+z).value=http://stackoverflow.com/questions/15625573/=ans[z]){document.getElementById('correct' + z).style.visibility='visible'document.getElementById('incorrect' + z).style.visibility='hidden'}if (document.getElementById('response'+z).value!=ans[z] && document.getElementById('response'+z).value!=''){document.getElementById('correct' + z).style.visibility='hidden'document.getElementById('incorrect' + z).style.visibility='visible'}if (document.getElementById('response'+z).valuehttp://stackoverflow.com/questions/15625573/==''){document.getElementById('correct' + z).style.visibility='hidden'document.getElementById('incorrect' + z).style.visibility='hidden'}}</script><img id="correct0"src="http://stackoverflow.com/questions/15625573/correct.jpg"style="visibility:hidden"/><img id="incorrect0"src="http://stackoverflow.com/questions/15625573/incorrect.jpg"style="visibility:hidden"/>1a <textarea style="width: 100px; height: 20px;"id="response0"></textarea><button style="height: 20px"onclick="check(0)">check</button><br></br><img id="correct1"src="http://stackoverflow.com/questions/15625573/correct.jpg"style="visibility:hidden"/><img id="incorrect1"src="http://stackoverflow.com/questions/15625573/incorrect.jpg"style="visibility:hidden"/>1b <textarea style="width: 100px; height: 20px;"id="response1"></textarea><button style="height: 20px"onclick="check(1)">check</button><br></br>\[/code\]This works but is obviously very clunky (I have in fact used an Excel spreadsheet to generate the html code). My questions are: Can I use javascript itself to generate the textboxes and buttons? Can I obfuscate the correct answers (if a pupils knows how to view the source of my webpage, it's game over for my exam!).Many thanks and best wishes,
 
Back
Top