Focus on Answer

Focus on Answer

shawn hamzee -
Atsakymų skaičius: 5
Tim,

Would you be able to tell me where in the quiz mod the answer field is generated? I have looked all around and do not see where the answer field is being generated.
I want to be able to manipulate the focus in the answer field after each question has been submitted by the kids in quiz format of a question per page. I can see in the page source that the field name for the answer(s) are generated dynamically but can't find where exactly that is being done.

I'd thought to put a simple js as follows:

window.onload=function() {
x = document.getElementsByTagName('input')[0];
if (x.value == '') x.focus();
}

in the attempt.php and tried it; however, it did not work.

thanks for helping.
Įvertinimų vidurkis: -
Atsakymas į shawn hamzee

Re: Focus on Answer

Joseph Rézeau -
Core developers paveikslėlis Particularly helpful Moodlers paveikslėlis Plugin developers paveikslėlis Testers paveikslėlis Translators paveikslėlis

Hi Shawn, Here is the answer (tested with Moodle 1.6.3).

In file \mod\quiz\attempt.php, towards line 92, change this:

print_header_simple(format_string($quiz->name), "",
"<a href=\"index.php?id=$course->id\">$strquizzes</a> ->
<a href=\"view.php?id=$cm->id\">".format_string($quiz->name)."</a> -> $strattemptnum",
"", "", true, $strupdatemodule);

to that:

print_header_simple(format_string($quiz->name), "",
"<a href=\"index.php?id=$course->id\">$strquizzes</a> ->
<a href=\"view.php?id=$cm->id\">".format_string($quiz->name)."</a> -> $strattemptnum",
"", "", true, $strupdatemodule, "", "",
"Xonload=\"javascript: xx = document.getElementsByTagName('input');for (i=0; i<xx.length-1; i++) { if ( (xx[i].type == 'text') && ( xx[i].name.substr(0,4) == 'resp') ) { xx[i].focus(); i=xx.length; } }\"");

Joseph

Note.- Of course in the added code lines the X which is added to onload by Moodle on this forum should be removed...

Atsakymas į Joseph Rézeau

Re: Focus on Answer

shawn hamzee -
Joseph,
Thanks for helping me out. The code works perfectly even in 1.7. I added it and tested it. What's more is that now (I guess with this code in) when the kid types an answer in the response field and hits the return key, the quiz module advances to the next question in the quiz thereby saving the kid from clicking on and on and on. This is a big time saver that I think humbly should be included in the production code.

Thanks much.
Atsakymas į shawn hamzee

Re: Focus on Answer

Joseph Rézeau -
Core developers paveikslėlis Particularly helpful Moodlers paveikslėlis Plugin developers paveikslėlis Testers paveikslėlis Translators paveikslėlis
Shawn > when the kid types an answer in the response field and hits the return key, the quiz
module advances to the next question in the quiz thereby saving the kid from clicking on and on and on...

I do not see this behavior either in 1.6 or 1.7. What are your quiz settings ? adaptative mode on/off? 1 question per page? Students may review: etc.

What I see is that when a student enters his answer and hits RETURN the focus remains in the answer input text field. Are you quite sure that pressing Enter makes the quiz proceed to the next question page?

Joseph

Atsakymas į Joseph Rézeau

Re: Focus on Answer

shawn hamzee -

Joseph,

I left work a couple of hours ago; however, tomorrow I'll do some more testing to make sure and will subsequently let you know. I had made some changes previously and this particular behavior can be the result of those changes.

Thanks

Atsakymas į Joseph Rézeau

Re: Focus on Answer

shawn hamzee -
Joseph,

I did some more testing: here is what I had done to make the return key work:
in the quiz definition page I have: (the ones that pertain are listed)
question per page: 1
shuffle question: yes
adaptive mode: no
apply penalty: no
also, i unchecked all the boxes for feedback (student may review) for the entire quiz. this seems to be the important one.

once these setting are saved, the kids can easily just hit the return key to advance to the next page (question) after typing their answer to the current question.

i should also mention that previously i had added a button called "Next" to the attempt page because I hadn't figured this out just yet. The button does exactly the same thing that the link "Next" does albeit in the button format. I am not sure what impact this can have though on the function of the return key.

Hope this helps clear it.