--- loncom/homework/radiobuttonresponse.pm	2007/02/22 01:25:31	1.111
+++ loncom/homework/radiobuttonresponse.pm	2007/03/27 19:20:49	1.113
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.111 2007/02/22 01:25:31 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.113 2007/03/27 19:20:49 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -180,6 +180,9 @@ sub end_foilgroup {
 	if ( $style eq 'survey'  && $target ne 'analyze') {
 	    if ($target eq 'web' || $target eq 'tex') {
 		$result=&displayallfoils($direction, $target);
+		if ($target eq 'web') {
+		    &setup_prior_tries_hash();
+		}
 	    } elsif ( $target eq 'answer' ) {
 		$result=&displayallanswers();
 	    } elsif ( $target eq 'grade' ) {
@@ -193,6 +196,9 @@ sub end_foilgroup {
 						       $safeeval,'-2');
 	    if ($target eq 'web' || $target eq 'tex') {
 		$result=&displayfoils($target,$max,$randomize,$direction);
+		if ($target eq 'web') {
+		    &setup_prior_tries_hash();
+		}
 	    } elsif ($target eq 'answer' ) {
 		$result=&displayanswers($max,$randomize);
 	    } elsif ( $target eq 'grade') {
@@ -231,6 +237,20 @@ sub getfoilcounts {
     return ($truecnt,$falsecnt);
 }
 
+sub setup_prior_tries_hash {
+    my $part=$Apache::inputtags::part;
+    my $id=$Apache::inputtags::response[-1];	
+    foreach my $i (1..$Apache::lonhomework::history{'version'}) {
+	my $key = "$i:resource.$part.$id.submission";
+	next if (!exists($Apache::lonhomework::history{"$key"}));
+	my %response = 
+	    &Apache::lonnet::str2hash($Apache::lonhomework::history{$key});
+	my ($name) = keys(%response);
+	$Apache::inputtags::submission_display{$key} = 
+	    $Apache::response::foilgroup{$name.'.text'}
+    }
+}
+
 sub displayallfoils {
     my ($direction, $target)=@_;
     my $result;
@@ -290,7 +310,11 @@ sub displayallfoils {
 		    $i++;
 		} else {
 		    $result .= '<label>';
-		    $result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
+		    $result.="<input
+                       onchange=\"javascript:setSubmittedPart('$part');\"
+                       type=\"radio\"
+                       name=\"HWVAL_$Apache::inputtags::response['-1']\"
+                       value=\"$temp\" ";
 		    if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
 		    $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
 			'</label>';
@@ -508,7 +532,11 @@ sub displayfoils {
 	    }
 	    if ($target ne 'tex') { 
                 $result.= '<label>';
-		$result.="<input type=\"radio\" name=\"HWVAL_$Apache::inputtags::response['-1']\" value=\"$temp\" ";
+		$result.=
+		    "<input type=\"radio\"
+                            onchange=\"javascript:setSubmittedPart('$part');\"
+                            name=\"HWVAL_$Apache::inputtags::response['-1']\"
+                            value=\"$temp\" ";
 		if (defined($lastresponse{$name})) { $result .= 'checked="on"'; }
 		$result .= ' />'.$Apache::response::foilgroup{$name.'.text'}."</label>";
 	    } else {