Jump to content

How to automatically display data in textboxes?


srijon

Recommended Posts

Hi, I am trying to create a page where teachers will be able to input marks.  So far what I have managed to develop is like this- the page shows the list of students with their names and roll numbers in the first and second column. In the third column, there is a text box to input the obtained marks and once it is filled and the user moves to the next textbox, I intend it to automatically calculate the grades and GPAs and show in the four and five column in two text boxes and here I am stuck now. To automatically calculate GPA I have coded a javascript function, but the problem is it shows GPA and Grade only for the student who is on the very top of the list. It doesn’t work for rest of the students or you can say textboxes.  Would you please kindly help me to solve this problem?

 

I have snapshot of the problem. here is the link - http://oi56.tinypic.com/2622vpf.jpg and i have attached it with this message also. 

Thanks in Advance

 

 

Here is the code that I have developed so far-

<html>

<head>

</head>
<body>
<form name="form" action="ball.php" method="post">
Total Mark <input size="5" id="totalmark" type="text" name="totalmark" value=""/>
<table align="center" border="0" width="70%">
   <tr class="table_head">
   <td width="37%"><div align="center"><strong><span class="style3">Student Name </span></strong></div></td>
   <td width="22%"><div align="center"><strong><span class="style3">Student ID </span></strong></div></td>
   <td width="21%"><div align="center"><strong><span class="style3">Obtained Mark</span></strong></div></td>
   <td width="20%"><div align="center"><strong><span class="style3">Grade</span></strong></div></td>
   <td width="20%"><div align="center"><strong><span class="style3">GPA</span></strong></div></td>
   <td width="20%"><div align="center"><strong><span class="style3">Status</span></strong></div></td>
   </tr>   

<?PHP
include("connect.php");
$query = "SELECT * FROM student WHERE batch= 'Eight-A' ";
$result = mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$studentname = mysql_result($result,$i,"studentname");
$studentid = mysql_result($result,$i,"studentid");


?>

<tr style="background:<?=(($i%2)?'#ddd':'#eee')?>">
<td><div align="center"><span class="style3"><a href="studentprofile.php?studentid=<? echo $studentid?>"><? echo $studentname ?></a></span></div></td>
<td><div align="center"><span class="style3"><input type="hidden" name="studentid[]" value="<? echo $studentid?>"><? echo $studentid?> </span></div></td>
<td><div align="center"><span class="style3"><input id="obtainedmark[]" onBlur="recalculateSum();" size="5" type="text" name="obtainedmark[]" value=""/></span></div></td>
<td><div align="center"><span class="style3"><input id="grade" size="5" type="text" name="grade" value=""/></span></div></td>
<td><div align="center"><span class="style3"><input id="gradepoint" size="5" type="text" name="gradepoint" value=""/></span></div></td>

<? include('pullgradesinfo.php'); ?>
<script language="javascript">

   function recalculateSum()
    {
        var num1 = parseFloat(document.getElementById("obtainedmark").value);
        var num2 = parseFloat(document.getElementById("totalmark").value);
      
      if (num1 > num2)
  {

   alert('The obtained mark suppose to be lesser than the Total Mark');
        return false;
  }
   else
           {
        var num3= ((num1/ num2)*100).toFixed( 1 ) ;
      
      
      if (num3 >="<?= $mark1?>" ) {var gradepoint= "<?=$gradepoint1?>"; var grade="<?=$grade1?>";}
      if (num3 ==100 ) {var gradepoint= "<?=$gradepoint1?>"; var grade="<?=$grade1?>";}
      if (num3 >="<?= $mark2?>" && num3 < "<?=$mark1?>" ) {var gradepoint="<?=$gradepoint2?>"; var grade="<?=$grade2?>";}
      if (num3 >="<?= $mark3?>" && num3 < "<?=$mark2?>" ) {var gradepoint="<?=$gradepoint3?>"; var grade="<?=$grade3?>";}
      if (num3 >="<?= $mark4?>" && num3 <"<?= $mark3?>" ) {var gradepoint="<?=$gradepoint4?>"; var grade="<?=$grade4?>";}
      if (num3 >="<?= $mark5?>" && num3 < "<?=$mark4?>" ) {var gradepoint="<?=$gradepoint5?>"; var grade="<?=$grade5?>";}
      if (num3 >="<?= $mark6?>" && num3 <"<?= $mark5?>" ) {var gradepoint="<?= $gradepoint6?>"; var grade="<?=$grade6?>";}
      if (num3 >="<?= $mark7?>" && num3 <"<?= $mark6?>" ) {var gradepoint="<?=$gradepoint7?>"; var grade="<?=$grade7?>";}
      if (<?= $mark7?> > num3 ) {var gradepoint="<?=$gradepoint7?>"; var grade="<?=$grade7?>";}

      
      document.getElementById("grade").value = (grade);
      document.getElementById("gradepoint").value = (gradepoint);
      
      
   
      }   
      
       
   
   }   

</script>
<td><div align="center"><span class="style3"><select name="status[]"> <option value="Present">Present </option>  <option value="Absent">Absent </option></select></span></div></td>
</tr>



<a href="in.ph" > </a>
<?
++$i; } } else { echo "No Record Found"; }


?> 
<tr> <td><input type="submit" value="Submit" name="Submit"> </td></tr>
</table>
<input type="hidden" name="highestmark" value="20"/> <input type="hidden" name="subject" value="Bangla 1"/>
<input type="hidden" name="examdate" value="2011-01-01"/>
<input type="hidden" name="examtype" value="Mid Term"/>
<input type="hidden" name="totalmark" value="20"/>
</form>
</body>
</html>

 

[attachment deleted by admin]

Link to comment
Share on other sites

function recalculateSum()
{
var num1 = parseFloat(document.getElementById("obtainedmark").value);

 

Can't do this. An ID can only be given once. Here the obtainedmark is generated for each student and therefore more than one. Also

<input id="obtainedmark[]" onblur="recalculateSum();" ....  The ID is obtainedmark[] and that's different then the obtainedmark.

 

Either use obtainedmark1, obtainedmark2, obtainedmark3, etc. or pass the value to the js function. The numbers are php generated.

Link to comment
Share on other sites

@Sunfighter.. At first many thanks for your reply. Actually since I have no idea about how many students will exactly be enrolled for a particular class, I don’t know how many obtainedmark1..2..3.. I should use. So i think passing the value to the JS function would be a good idea, but I am not sure how to do this. Would you please kindly brief me on how to do this?  :D

 

Thanks again for your help.

Link to comment
Share on other sites

I am so sorry this has taken this long to get back to you. I had something come up that needed my attention and I did not have time to respond.

 

In reality you do know how many students you have. This line => $num = mysql_num_rows($result); from:

$query = "SELECT * FROM student";
$result = mysql_query($query);
$num = mysql_num_rows($result);

$num is the number of students. So as not to confuse matters I have made another variable to represent the number of students => $idNum and used it to generate $studentid that will give you a unique Id for each student. I placed it in the following code and echoed it to the 'Obtained Mark' column. You should be able to take it from here and do the calculations.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>New document</title>
<meta name="generator" content="TSW WebCoder 2010" />
<script type="text/javascript">
function getGrade(some)
{
message = document.getElementById(some).innerHTML;
alert(message);
}
</script>
</head>
<body>
<form id="form" action="ball.php" method="post">
Total Mark <input size="5" id="totalmark" type="text" name="totalmark" value=""/>
<table id="table-1" border="0" width="70%" style="text-align: center;">
<tr class="table_head">
   <td style="width: 37%;"><div style="text-align: center;"><strong><span class="style3">Student Name </span></strong></div></td>
   <td style="width: 22%;"><div style="text-align: center;"><strong><span class="style3">Student ID </span></strong></div></td>
   <td style="width: 21%;"><div style="text-align: center;"><strong><span class="style3">Obtained Mark</span></strong></div></td>
   <td style="width: 20%;"><div style="text-align: center;"><strong><span class="style3">Grade</span></strong></div></td>
   <td style="width: 20%;"><div style="text-align: center;"><strong><span class="style3">GPA</span></strong></div></td>
   <td style="width: 20%;"><div style="text-align: center;"><strong><span class="style3">Status</span></strong></div></td>
</tr>

<?php
//include('pullgradesinfo.php');
//include("connect.php");
require ('./inc/it_connect.php');
$query = "SELECT * FROM student";
$result = mysql_query($query);
$num = mysql_num_rows($result);
//mysql_close();
if ($num > 0 )
{
$i=0;
$idNum = 0;
while ($i < $num)
{
	$studentname = mysql_result($result,$i,"studentname");
	$studentid = mysql_result($result,$i,"studentid");
	$idNum = $idNum + 1;
?>
<tr style="background:<?=(($i%2)?'#ddd':'#eee')?>">
<td>
<div style="text-align: center;">
<span class="style3">
<a href="studentprofile.php?studentid=<?php echo $studentid; ?>">
<?php echo $studentname; ?>
</a>
</span>
</div>
</td>

<td><div style="text-align: center;"><span class="style3"><input type="hidden" name="studentid[]" value="<?php echo $studentid; ?>" /><?php echo $studentid; ?> </span></div></td>




<td>
<input id="<?php echo $idNum; ?>"  onblur="getGrade('<?php echo $idNum; ?>');" size="5" type="text" value="<?php echo $idNum; ?>"/></td>




<td><div style="text-align: center;"><span class="style3">
<input id="grade" size="5" type="text" name="grade" value=""/></span></div></td>

<td><div style="text-align: center;"><span class="style3">
<input id="gradepoint" size="5" type="text" name="gradepoint" value=""/></span></div></td>

<td><div style="text-align: center;"><span class="style3"><select name="status[]">
<option value="Present">Present </option>  <option value="Absent">Absent </option></select></span></div></td>

</tr>
<a href="in.ph" > </a>
<?php
	++$i;
}
}else{
echo "No Record Found";
}
?>
<tr><td><input type="submit" value="Submit" name="Submit" /></td></tr>
</table>
<input type="hidden" name="highestmark" value="20"/>
<input type="hidden" name="subject" value="Bangla 1"/>
<input type="hidden" name="examdate" value="2011-01-01"/>
<input type="hidden" name="examtype" value="Mid Term"/>
<input type="hidden" name="totalmark" value="20"/>
</form>
</body>
</html>

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.