WeBWorK Problems

Answer fields shown in dependance of the answer of another answer field

Answer fields shown in dependance of the answer of another answer field

by F. Heiderich -
Number of replies: 3
Is it currently possible in WeBWorK to show answer fields in dependence of the answer to another field?

Think of a problem as the following:

Is the element k + n Z invertible in Z/nZ? If so, determine its inverse.

It would be nice if the student would see a dropdown list with values such as "invertible" and "not invertible". If he selects "invertible", an additional textbox would be shown where he would be asked to insert the inverse of this element.

I have seen a few problems of this kind. Usually they ask the student to enter a specified string such as "not invertible" in the additional textbox. This works, but it is not really nice.
In reply to F. Heiderich

Re: Answer fields shown in dependance of the answer of another answer field

by Michael Gage -
It would be nice if the student would see a dropdown list with values such as "invertible" and "not invertible". If he selects "invertible", an additional textbox would be shown where he would be asked to insert the inverse of this element.

I think it's possible but there is not internal support that makes it easy. I believe that what you describe can be implemented in a normal webpage using javaScript. You can add javaScript to a webwork problem as well and when
the submit button is pressed the javaScript can make sure that all of the answers are submitted with the form.

I agree this would be cool, and with a bunch of desirable problems as examples, javaScript subroutines could be designed that make this behavior easy to implement. The geogebra and applet problems provide early versions of examples in this direction. (They were designed several years ago when javaScript was not as well developed so those can almost certainly be improved.)
I can't think of other examples off hand.
In reply to Michael Gage

Re: Answer fields shown in dependance of the answer of another answer field

by Paul Pearson -
Hi,

You do not need two answer blanks for this. You can have one answer blank and prompt students to enter the inverse (if it's invertible) and otherwise enter the string "not invertible". This is done by adding strings to the context, as in the following examples:

http://webwork.maa.org/wiki/StringsInContext

http://webwork.maa.org/wiki/StringOrOtherType1

Also, you can use scaffold.pl to create a question with multiple sections, and control which sections get revealed depending upon the student's answers:

http://webwork.maa.org/wiki/Scaffolding2

Or, you could create a PopUp menu with options from the list ["0","1","2", ..., "p-1", "not invertible"]:

http://webwork.maa.org/wiki/MultipleChoicePopup2


Best regards,

Paul Pearson

In reply to Paul Pearson

Re: Answer fields shown in dependance of the answer of another answer field

by F. Heiderich -
Thank you for these suggestions. In this particular example one could probably use either of the techniques suggested by Paul Pearson to implement the problem properly. I was however thinking of such a mechanism for more general situations and the one proposed here was merely an example (maybe it was too simple to properly illustrate the problem). I should have a closed look at Scaffolding2. It seems to be the most flexible approach.