User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 332,663 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,349 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 420 | Replies: 1
Reply
Join Date: Mar 2008
Posts: 3
Reputation: HenryForbes is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
HenryForbes HenryForbes is offline Offline
Newbie Poster

Question non calculating values

  #1  
Mar 5th, 2008
Help,
I have a web based form containg values typed in by the user. The first value is called noItems, which is outside the form. The form contains a persons name, the number of items,noSub, thay have submitted and their final grade. I need to use noItems and noSub to calulate their prcentage and store it in the grade column of the table. How do I use a command button to, when clicked, go through the data on the table and calculate the final grade(as a percentage for each row? When it is run all the fields just go blank.
my code is below:
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <!--#include file="Connections/conn_3_coast.asp" -->
  3. <%
  4. Dim rs_homework
  5. Dim rs_homework_cmd
  6. Dim rs_homework_numRows
  7.  
  8. Set rs_homework_cmd = Server.CreateObject ("ADODB.Command")
  9. rs_homework_cmd.ActiveConnection = MM_conn_3_coast_STRING
  10. rs_homework_cmd.CommandText = "SELECT DISTINCT tblStudent.Name, studentResults.enrolno FROM tblStudent INNER JOIN studentResults ON tblStudent.enrolno = studentResults.enrolno ORDER BY tblStudent.Name"
  11. rs_homework_cmd.Prepared = true
  12.  
  13. Set rs_homework = rs_homework_cmd.Execute
  14. rs_homework_numRows = 0
  15. %>
  16. <%
  17. Dim Repeat1__numRows
  18. Dim Repeat1__index
  19.  
  20. Repeat1__numRows = 25
  21. Repeat1__index = 0
  22. rs_homework_numRows = rs_homework_numRows + Repeat1__numRows
  23. %>
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <head>
  27. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  28. <title>Untitled Document</title>
  29. <script type="text/javascript">
  30. <!--
  31. function calcGrade(){
  32. var tbl=document.getElementById('tblgrades');
  33. var tbl1=document.getElementById('tblNhwks_per');
  34. var trs1=tbl1.getElementByTagName('tr');
  35. var trs=tbl.getElementByTagName('tr');
  36. var tds1=tr[1].getElementsByTagName('td');
  37. var noHomeworks = tds1.noHomeworks;
  38. for (var i=0;i<trs.length;i++)
  39. {
  40. //get all the tds in this tr
  41. var tds=tr[i].getElementsByTagName('td');
  42. for (var j=0;j<tds.length;j++)
  43. {
  44. var pcag=(tds.submitted/noHomeworks)/100;
  45. if pcage<50
  46. tds.Grade=3;
  47. if ((pcage>
  48. =50) and (pcage<=84))
  49. tds.Grade=2;
  50. if pcage<84
  51. tds.Grade=1;
  52. }
  53.  
  54. }
  55. function MM_callJS(jsStr) { //v2.0
  56. return eval(jsStr)
  57. }
  58. //-->
  59. </script>
  60. </head>
  61.  
  62. <body>
  63. <h1>Coast@JCC</h1>
  64. <h1>Homework</h1>
  65. <form id="form2" name="form2" method="post" action="">
  66. <table width="293" border="1" id="tblNhwks_per">
  67. <tr>
  68. <td width="175">Number of Homeworks this period</td>
  69. <td width="102"><input type="text" name="noHomeworks" id="noHomeworks" /></td>
  70. </tr>
  71. </table>
  72. </form>
  73. <p>&nbsp;</p>
  74. <form id="form1" name="form1" method="post" action="">
  75. <table width="596" border="1" id="tblgrades">
  76. <tr>
  77. <td width="201">Name</td>
  78. <td width="107">Enrolment Number</td>
  79. <td width="131">Homeworks Submited</td>
  80. <td width="129">Grade</td>
  81. </tr>
  82. <tr>
  83. <%
  84. While ((Repeat1__numRows <> 0) AND (NOT rs_homework.EOF))
  85. %>
  86. <td><%=(rs_homework.Fields.Item("Name").Value)%> </td>
  87. <td><%=(rs_homework.Fields.Item("enrolno").Value)%> </td>
  88. <td><input type="text" name="submitted" id="submitted" /></td>
  89. <td><input type="text" name="hwkGrade" id="hwkGrade" /></td><tr></tr>
  90. <%
  91. Repeat1__index=Repeat1__index+1
  92. Repeat1__numRows=Repeat1__numRows-1
  93. rs_homework.MoveNext()
  94. Wend
  95. %>
  96. <td height="110"></tr>
  97. </table>
  98. </form>
  99. <form id="form3" name="form3" method="post" action="">
  100. <input name="Calculate" type="submit" id="Calculate" onclick="MM_callJS('calcGrade()')" value="Submit" />
  101. </form>
  102. <form id="form4" name="form4" method="post" action="">
  103. </form>
  104. <p>&nbsp;</p>
  105. <p>&nbsp;</p>
  106. <p>Page title goes here</p>
  107. <p>&nbsp;</p>
  108. <p>Page title goes here</p>
  109. <p>&nbsp;</p>
  110. <p>&nbsp;</p>
  111. </body>
  112. </html>
  113. <%
  114. rs_homework.Close()
  115. Set rs_homework = Nothing
  116. %>
Last edited by peter_budo : Mar 6th, 2008 at 5:28 am. Reason: Please use [code] tags as to make easier to read your post
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,224
Reputation: MidiMagic is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 76
MidiMagic's Avatar
MidiMagic MidiMagic is online now Online
Nearly a Posting Maven

Re: non calculating values

  #2  
Mar 7th, 2008
You have unescaped < and > characters in your js code. The web browser is confused by these. Make your js an external .js file, and it might fix this.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC