
|
<SCRIPT>
function tester(form) {var percent; var correct = 0; if (form[0]. checked == true) correct++; // OR if (form.No1[0].checked == true) correct++;if (form[3].checked == true) correct++; // OR if (form.No2[1].checked == true) correct++; if (form[5].checked == true) correct++; // etc... if (form[6].checked == true) correct++; if (form[9].checked == true) correct++; percent = (correct / 5) * 100; if (percent == 100) alert("You got a " + percent + "%. Great Job!"); if (percent < 100) alert("You
got " + correct + " out of 5 correct ( " + percent +
"% )"); < /SCRIPT> When the Submit button get pressed the onSubmit Event Handler is initiated. onSubmit calls the function tester(this) and also has a return false which causes "nothing" to happen. In other words, return false overwrites the default behavior of submitting the Form's Information to the server.<FORM onSubmit="tester(this); return false;">1. George Washington was the first president of the United States. <INPUT TYPE="radio" NAME="No1">False 2. Tucson is the capital of Arizona. 3. Guam is an island in the Caribbean. 4. JavaScript is easier to learn than Java. 5. Mhz refers to how much memory a computer
has. <INPUT TYPE="Submit" VALUE="Get Score"> <INPUT TYPE="Reset" VALUE="Clear"> |