Jump to content

Autosum listboxes


Donovan

Recommended Posts

I have a peer evaluation that students fill out. The number of members in their group is somewhere between 5 to 7. When a user clicks on the course record for peer evaluation it pulls all the groups members for that user and displays them with a drop down box and textarea. The drop down is a eval score between 7 - 13. The textarea is for eval comments for feedback on how well each member participated and contributed to the groups success.

 

The following code pulls all group members from the users group excluding themselves, then displays the form drop down boxes so that the user can select a score for each member, and leave a feedback comment.

while($row = $db->sql_fetchrow($getgroupmembers)) {
$SOMS_KEY = $row['SOMS_KEY'];
$UID = $row['UID'];
$Name_First = $row['Name_First'];
$Name_Last = $row['Name_Last'];
echo"<tr>"
    ."<td align='center'> $Name_First $Name_Last  </td>"
    ."<td>"    
    ."<select name='evalscore[{$UID}]'>"
    ."<option value='7' selected>7</option>"
    ."<option value='8'>8</option>"
    ."<option value='9'>9</option>"
    ."<option value='10'>10</option>"
    ."<option value='11'>11</option>"
    ."<option value='12'>12</option>"
    ."<option value='13'>13</option>"
    ."</select>"
    ."</td>"   
    ."<td align='left'><textarea name ='evalcomment[{$UID}]' cols='100' colspan='1' rows='2'></textarea></td>"   
    ."</tr>";    
} 
$countgroupmembers = $db->sql_query("SELECT * FROM ".$prefix."_tl_group_students WHERE Group_ID = '$UserGroup'");
$grouptotal = $db->sql_numrows($countgroupmembers);
if ($grouptotal == 7) {
$Total_Points = 60;
} elseif ($grouptotal == 6) { 
$Total_Points = 50;
} elseif ($grouptotal == 5)  {
$Total_Points = 40;
}
echo "<tr><td align='left'> Total Points Must = $Total_Points</td>"; 

 

This gets sent to another function where I write the values and display some sort of confirmation.


function TLInsertY1PeerEvals($authuser) {
global $prefix, $db;
include("header.php");
session_start();
if (isset($_SESSION['authuser'])) {
$authuser = $_SESSION['authuser']; 
}  
foreach ($_POST['evalscore'] as $keyUID => $score) {
    //Refer to the evalcomment array using the evalscore index (which is $keyUID in this case)    
   $Course_Number = $_POST['Course_Number'];   
   $evalcomment = $_POST['evalcomment'][$keyUID];   
   $sql = "INSERT INTO ".$prefix."_tl_peereval (UID, evalscore, eval_comment, Course_Number, rater, datesubmit)". "VALUES ('$keyUID', '$score', '$evalcomment', '$Course_Number', '$authuser', NOW())";
$result = $db->sql_query($sql);
if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");} 
  }
  include("header.php");
     OpenTable();
    echo "<br>\n"    
    ."<form action='".$_server['php_self']."' method='post'"        
    ."<table border=\"0\">"
    ."<tr><td>Thank You for submitting your peer evaluation.</td></tr>"
    ."<tr><td><input type=\"hidden\" name=\"op\" value=\"TLStudentGrades\">\n"
    ."<input type=\"submit\" value=\"Continue\"></form></td></tr></table><br>\n\n";    
    CloseTable(); 
    include("footer.php");
  }

 

I assume I need javascript but have found no javascript examples I can follow. The problem is the form is dynamic depending on number of group members. If I had a static form I could just SUM the form elements....

 

<select id="evalscore_1" name="evalscore_1"

...

<select id="evalscore_2" name="evalscore_2"

etc

 

But my form is not static.  It could have anywhere from 4 members per group up to 7 members per group.

 

What I need is to SUM all my eval_scores for each of the group members then compare that to what the average (Total_Points) should be.

 

Example:

 

Tim = 11

Nick = 12

Bob = 8

Lauren = 10

Steve = 9

 

$SUM_Points = 50

 

Then validate that $Total_Points and $SUM_Points match as well as each comments has a value.

 

What would be ideal is a visible javascript running total of each listbox onchange() event.

 

If anybody can assist it would be greatly appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.