Jump to content

Need javascript to SUM listboxes


Donovan

Recommended Posts

I have a program I am working on that allows students to submit "Peer Evaluations" for their team members for a college course.  They could have anywhere from 5 to 7 members per team which is pulled from a MySQL database.

 

The minimum score is 7 while the max is 13.

 

I have code that figures out what the sum should be but I would like a running total taken from the listboxes.  The running total should show up in $SUM_Points.

 

If anybody can help me figure this out i would appreciate it.

 

Here is my code.

function peerEvals() {
global $stop, $prefix, $db, $authuser;
include("header.php");
OpenTable();
$Course_ID = $_GET['Course_ID'];
$getcoursename = $db->sql_query("SELECT Course_Name FROM ".$prefix."_tl_courses WHERE Course_ID = '$Course_ID'");
if (!$getcoursename) {
	echo("<p>Error performing query: " . mysql_error() . "</p>");
	exit();   
	}

while($info = $db->sql_fetchrow($getcoursename)) {
$Course_Name  = $info[Course_Name];
}

echo"<table width=\"100%\" border=\"0\" cellpadding=\"3\">"
  ." <tr><td align=\"center\">Team Based Learning - Peer Evaluation</td></tr>"  
  ." <tr><td align=\"center\">Course: $Course_Name</td></tr>"
  . "</table>";  
  echo"<table width=\"100%\" border=\"0\" cellpadding=\"3\">"
  ." <tr><td><b>Assigning Fair Peer Evaluation Scores<b></td></tr>"
  ."<tr><td><p>Assign an Average of 10 points to your other members of your team (ie NOT including yourself.) You should assign a total of 40 points for a five-member team or 50 points for a six-member team.  The minimum possible score for a team member is 7 and the maximum possible score is 13.  Assign scores to reflect how you feel about the extent to which the other member contributed to your learning and/or your teams performance.  This is an opportunity to reward the members of your teamn who actually worked hard on your behalf.  </p></td>";
  echo"<tr><td><b>Providing Helpful Feedback Comments<b></td></tr>"
  ."<tr><td><p>In addition to assigning peer evaluations scores, you must provide writtten peer feedback to EACH member of your team. When giving feedback, keep in mind the seven characteristcs of Helpful Feedback:</td></tr>";
  echo"<tr><td>"
  ."<OL>"
  ."<LI>Descriptive, not evaluative, and is "owned" by the sender."
  ."<LI>Specific, not general."
  ."<LI>Honest and sincere."
  ."<LI>Expressed in terms relevent to the self-perceived needs of the receiver."
  ."<LI>Timely and in context."
  ."<LI>Desired by the receiver, not imposed on him or her."
  ."<LI>Usable, concerned with behavior over which the receiver has control."
  ."</OL>"
  ."<b></td></tr>";
  echo"</table>";
  CloseTable();
  $findusergroup = $db->sql_query("SELECT Group_ID FROM ".$prefix."_tl_group_students WHERE LDAP_USER = '$authuser'");
  while($info = $db->sql_fetchrow($findusergroup)) {
$UserGroup = $info[Group_ID]; 
} 
  
  OpenTable();
  echo"   <form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">"
  . "     <table width='100%' border='1' cellpadding='3'>"
  . "       <tr><td colspan='3' align='center'>Group: $UserGroup</td><tr>"
  . "		<tr>"
  . "         <td>Team Member</td>"
  . "         <td>Score</td>"
  . "         <td>Helpful Feedback</td>"
  . "       </tr>";
  $getgroupmembers = $db->sql_query("SELECT s.Name_First, s.Name_Last, s.SOMS_KEY, s.UID, gs.LDAP_USER FROM ".$prefix."_tl_group_students gs LEFT JOIN ".$prefix."_tl_students s ON s.SOMS_KEY = gs.SOMS_KEY  
WHERE gs.Group_ID = '$UserGroup'
AND gs.LDAP_USER != '$authuser'");
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'>"
    ."<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' cols='100' colspan='1' rows='2'></textarea></td>"   
    ."</tr>";
} 
$countgroupmembers = $db->sql_query("SELECT * FROM ".$prefix."_tl_group_students WHERE gs.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>";
echo "<td align='left'>$SUM_Points</td></tr>";
echo "<input type='hidden' name='SOMS_KEY' value='$SOMS_KEY'>\n"; 
echo "<input type='hidden' name='UID' value='$UID'>\n";
echo "<input type='hidden' name='Course_ID' value='$Course_ID'>\n";
echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"Submit\" name=\"TLInsertPeerEvals\" value=\"Submit\"></td></tr>";	
  echo"</table>";
  echo"</form>";  
CloseTable();
include("footer.php");
}

 

 

 

Link to comment
Share on other sites

You are asking for help with creating a JavaScript function, correct? JavaScript is run within client-side code. What you have posted above is server-side code. It is very difficult to try and write JS code against server-side code. The server-side code should be run to produce the output that will be delivered to the browser (e.g. HTML) so that the JS can be created. You can then implement the JS code into your server-side code.

 

I can't run the code above as I do not have the appropriate database set up. All you need to do is run the page above through your browser and post the output (i.e. the page source).

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.