473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

JavaScript not working if <form> is used

In this code i have placed a javascript for calculating numbers, total and %age. But when i am using form the javascript calling is not working,

is there any solution......

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Staff</title>
  6. <?php include'header2.php' ?>
  7. <?php 
  8.     session_start();
  9.         $connection = mysql_connect('localhost', 'root', '123');
  10.         $con        = mysql_select_db('new_db',$connection);
  11.  
  12.             if (isset($_POST['submit']))
  13.             {    
  14.             $insert = "INSERT INTO result SET name = '".$_POST['name']."',
  15.                                                   math = '".$_POST['math']."',
  16.                                                   english = '".$_POST['eng']."',
  17.                                                   hindi= '".$_POST['hindi']."',
  18.                                                   science = '".$_POST['science']."',
  19.                                                   art = '".$_POST['art']."',
  20.                                                   total = '".$_POST['total']."',
  21.                                                   percentage = '".$_POST['pecentage']."',
  22.                                                   passfail= '".$_POST['passfail']."'";
  23.  
  24.             $query = mysql_query($insert) or die (mysql_error());
  25.             header('location:result.php');
  26.             }
  27. ?>
  28.  
  29. </head>
  30. <script>
  31.     function total()
  32.             {
  33.                          var math =    parseInt(document.getElementById('math').value);
  34.                         var eng  =  parseInt(document.getElementById('eng').value);
  35.                         var hindi = parseInt(document.getElementById('hindi').value);
  36.                         var science = parseInt(document.getElementById('science').value);
  37.  
  38.                         var result = (math + eng + hindi + science);
  39.                         var percentage = (math + eng + hindi + science)/4;
  40.  
  41.                         document.getElementById('total').value=result;
  42.                         document.getElementById('percentage').value=percentage;
  43.  
  44.  
  45.  
  46.                          if (percentage<33)
  47.                              {
  48.  
  49.                                 document.getElementById('passfail').value="fail";
  50.                             }
  51.                         else if (percentage<50 || percentage<33)
  52.                             {
  53.                                 document.getElementById('passfail').value="Second Grade";
  54.                             }
  55.                         else if (percentage<80 || percentage<60)
  56.                             {
  57.                                 document.getElementById('passfail').value="First Grade";
  58.                             }
  59.                         else
  60.                             {
  61.                                 document.getElementById('passfail').value="Topper";
  62.                             }
  63.             }
  64. </script>
  65.  
  66. <style>
  67. .box
  68.         {
  69.             background-color:#871717;
  70.             width:300px;
  71.             margin-left:175px;
  72.             height:735px;
  73.         }
  74. .menubox
  75.         {
  76.             width:625px;
  77.             height:500px;
  78.             background-color:#FFF;
  79.             position:absolute;
  80.             top:150px;
  81.             left:550px;
  82.             opacity:.8;
  83.         }
  84. .result
  85.         {
  86.             font-family:Georgia, "Times New Roman", Times, serif;
  87.             font-size:16px;
  88.             font-style:italic;
  89.             font-weight:bold;
  90.             color:#FFF;
  91.             position:absolute;
  92.             top:250px;
  93.             left:250px;
  94.         }
  95. .sec
  96.         {
  97.             font-family:Verdana, Geneva, sans-serif;
  98.             font-size:12px;
  99.             color:#FFF;
  100.             position:absolute;
  101.             top:325px;
  102.             left:235px;
  103.             text-align:center;
  104.             width:175px;
  105.             font-style:italic;
  106.  
  107.         }
  108. .border1
  109.         {
  110.             border:1px solid #FFF;
  111.             position:absolute;
  112.             top:445px;
  113.             left:25px;
  114.             width:220px;
  115.         }
  116. fieldset
  117.         {
  118.             width:500px;
  119.             border-radius:5px;
  120.         }
  121. .res
  122.         {
  123.             position:absolute;
  124.             top:200px;
  125.             right:220px;
  126.  
  127.         }
  128. table
  129.         {
  130.             margin-left:80px;
  131.             margin-top:20px;
  132.             margin-bottom:20px;
  133.             text-align:center;
  134.             border-collapse:collapse;
  135.         }
  136.  
  137. input
  138.         {
  139.             width:150px;
  140.         }
  141.  
  142. </style>
  143. <body>
  144. <div class="box"></div>
  145. <div class="result">Students Results</div>
  146. <div class="menubox"></div>
  147. <div class="sec">Institue students results are displaying here.</div>
  148. <div class="border1"></div>
  149. <div class="res">
  150.     <fieldset >
  151.     <legend>Students Results</legend>
  152.  
  153.         <table>
  154.  
  155.                    <tr><td style="background-color:#69F; color:#FFF">Name<td style="background-color:#69F; color:#FFF; padding:5px 10px 5px 0"><input type="text" name="name" id="name" placeholder= "Student Name" /></td></td></tr>
  156.                 <tr><td style="background-color:#69F; color:#FFF">Math<td style="background-color:#69F; color:#FFF; padding:5px 10px 5px 0"><input type="text" name="math" id="math" placeholder= "Math Marks" /></td></td></tr>
  157.                 <tr><td style="background-color:#69F; color:#FFF">English<td style="background-color:#69F; color:#FFF; padding:5px 0 5px 0"><input type="text" name="eng" id="eng" placeholder= "English Marks" /></td></td></tr>
  158.                 <tr><td style="background-color:#69F; color:#FFF">Hindi<td style="background-color:#69F; color:#FFF; padding:5px 0 5px 0"><input type="text" name="hindi" id="hindi" placeholder= "Hindi Marks" /></td></td></tr>
  159.                 <tr><td style="background-color:#69F; color:#FFF">Science<td style="background-color:#69F; color:#FFF; padding:5px 0 5px 0"><input type="text" name="science" id="science" placeholder= "Science Marks" /></td></td></tr>
  160.                 <tr><td style="background-color:#69F; color:#FFF">Art<td style="background-color:#69F; color:#FFF; padding:5px 0 5px 0"><input type="text" name="art" id="art" placeholder= "Art Grades" /></td></td></tr>
  161.                 <tr><td style="background-color:#871717; color:#FFF">Total<td style="background-color:#871717; color:#FFF; padding:5px 0 5px 0"><input type="text" name="total" id="total" placeholder= "Average" onmouseover="return total()" /></td></td></tr>
  162.                 <tr><td style="background-color:#871717; color:#FFF">Percentage<td style="background-color:#871717; color:#FFF; padding:5px 0 5px 0"><input type="text" name="percentage" id="percentage" placeholder= "Percentage" onmouseover="return total()"  /></td></td></tr>
  163.                 <tr><td style="background-color:#871717; color:#FFF">Rank<td style="background-color:#871717; color:#FFF; padding:5px 0 5px 0"><input type="text" name="passfail" id="passfail" placeholder= "passfail"  onmouseover="return total()"/></td></td></tr>
  164.  
  165.  
  166.         </table>
  167.  
  168.       </fieldset>
  169.  
  170. </div>
  171. </body>
  172. </html>
  173.  
May 31 '13 #1
1 1307
Dormilich
8,658 Expert Mod 8TB
it’s working for me.
May 31 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bartosz Wegrzyn | last post by:
Please look at my code. I do validation of my form before I submit it. I want to be able to to press one form button without running validating script. I just want to go directly to my php...
0
by: irene | last post by:
Hi, I have an application that works well on my local server(xp) and it works fine on our company's web server(2003). But some buttons on the page(Javasript involved to do the validation) is not...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
2
by: AshuPd | last post by:
Hi all !!! I am fighting with a very interesting issue... What i need is to link a javasript with a imagebutton control which is already on a datalist. the problem is, if i place the control out...
2
by: kwenterprise | last post by:
Hello All, I am normally great at figuring out ways around iframe issues that frustrate us all. I am using javasript to try and break an iframe that I have a banner rotator embedded in but it...
18
by: sandeepdesai | last post by:
Hi.. i am new to javascripts, i am using a addRow scipt to add rows to a table dynamically. one of the cells(say cell2) in a Nth row needs to be hyperlinked to another script. for example: ...
2
by: pedalpete | last post by:
Hi All, I'm using Bill Scott's YUI carousel v5.6, and I've run into a crazy looping javascript for some reason, and I can't seem to get around it. The carousel loads a bunch of items, 7 of...
0
by: AshishatSAP | last post by:
Hi JSP experts, I am having a JSP in my project which has some scriptlet code in the start and then javascript follows. Inside the javasript the values of variables defined inside the scriptlet code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.