Page 1 of 1

How to automatically display data in textboxes?

Posted: Sun Aug 14, 2011 8:31 pm
by srijon
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>

Re: How to automatically display data in textboxes?

Posted: Mon Aug 15, 2011 5:26 am
by phphelpme
Is there a reason why you have to store these values in the database? In my opinion the Grade and GPA values are not required to be stored in your database at all.

I personally would have the php script use the 'Obtained Mark' value when retrieved from the database and run it through a for statement like:

if 'Obtained Mark equals less/morethan value X Grade = X and GPA = X. This way you store less in your database and have less calculations to do and you can scrap the java altogether.

Basically all you want to do is display the equivalent Grade and GPA that corresponds to the Obtained Mark. So build that into the php page as a for statement etc and save all the work your doing right now.

If you do this it will also be less confusing for the data entry clerk when filling in the form as your are displaying editable areas that the user does not need to edit in the first place. Even so you could have the php code work that out in the background when the submit button is clicked. That way it all happens without the user ever seeing it. I just dont get the need to show the data entry clerk the values as they are typing the Obtained Marks in. Surely when they are finished entering them they will run a report off or view a statement of some kind which you have created to the php code to display the data from the database.

So to me you have two options here:

1. Make the php code display the Grade and GPA values based on the Obtained Mark when a report is submitted.

2. Have the php code insert the values when the form is submitted etc without the user ever having to see values which are no use at that data entry moment.

Thats just my thoughts on the matter but I guess you need to answer the above question about storing these values in the database first?

Best wishes

Re: How to automatically display data in textboxes?

Posted: Fri Aug 19, 2011 3:34 am
by srijon
Thank you very much for your help. As you suggested I have made the page in a way that the teachers can only submit marks and they will not necessarily be able to see the grades instantly. Later on if they chose to see those results with grades and GPA, for that case I have developed PHP code which retrieves data from database and find out the obtained grades and GPAs and display . Thanks again. :)

Re: How to automatically display data in textboxes?

Posted: Fri Aug 19, 2011 5:04 am
by phphelpme
No problem at all. I am glad to have helped.

Sometimes just taking a step back and putting yourself in the teachers chair as the data entry person helps allot.

I totally agree with the solution I suggested and I am glad you took onboard my solution and since have scrapped javascript altogether because I happen to know that allot of schools for security disable java from running on most systems for added security.

Good luck with the rest of your project. If you need any more assistance or just guidance then please come back to the forum for a chat.

Best wishes