JavaScript Document Object Part – 3
Free Web development courses with real-time projects Start Now!!
Program 1
<html> <head><title>Java Script date Demo</title> <script language="javascript"> function validate() { var rn,name,p,c,m; rn=document.getElementById("STROLLNO").value; name=document.getElementById("STNAME").value; p=document.getElementById("STPHY").value; c=document.getElementById("STCHEM").value; m=document.getElementById("STMATH").value; if(rn=="") { alert("Roll No can not be blank") document.getElementById("STROLLNO").focus() return false; } if(name=="") { alert("Name can not be blank") document.getElementById("STNAME").focus() return false; } if(p=="") { alert("Physics marks can not be blank") document.getElementById("STPHY").focus() return false; } if(p>100 || p<0) { alert("Invalid physics marks") document.getElementById("STPHY").focus() return false; } if(c=="") { alert("Chemistry marks can not be blank") document.getElementById("STCHEM").focus() return false; } if(c>100 || c<0) { alert("Invalid chemistry marks") document.getElementById("STCHEM").focus() return false; } if(m=="") { alert("Maths marks can not be blank") document.getElementById("STMATH").focus() return false; } if(m<0 || m>100) { alert("Invalid maths marks") document.getElementById("STMATH").focus() return false; } document.writeln("<center>") document.writeln("<table border=1>") document.writeln("<tr><th>Roll No</th><th>Name</th><th>Physics</th><th>Chemistry</th><th>Maths</th></tr>") document.writeln("<tr>") document.writeln("<td>"+rn+"</td>") document.writeln("<td>"+name+"</td>") document.writeln("<td>"+p+"</td>") document.writeln("<td>"+c+"</td>") document.writeln("<td>"+m+"</td>") document.writeln("</tr>") document.writeln("<tr>") var total p=parseInt(p) c=parseInt(c) m=parseInt(m) total=p+c+m per=total/3 document.writeln("<td>Total:"+total+"</td>") document.writeln("<td>Percentage:"+per+"</td>") document.writeln("</tr>") document.writeln("</table>") document.writeln("</center>") } </script> </head> <body> <center> <form> <table border=1> <tr> <th>Roll No</th> <td><input type=text name=txtuser id="STROLLNO"></td> </tr> <tr> <th>Name</th> <td><input type=text name=txtname id="STNAME"></td> </tr> <tr> <th>Physics</th> <td><input type=text name=txtname id="STPHY"></td> </tr> <tr> <th>Chemistry</th> <td><input type=text name=txtname id="STCHEM"></td> </tr> <tr> <th>Maths</th> <td><input type=text name=txtname id="STMATH"></td> </tr> <tr> <td></td> <td><input type="button" value="Submit" onclick="return validate()"></td> </tr> </table> </form> </center> </body> </html>
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google