www.webdeveloper.com
Results 1 to 4 of 4

Thread: JavaScript error in Firebug

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    84

    JavaScript error in Firebug

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
    <title>Assignment 4 - JavaScript Conditional Variables</title>
    <head>
    <script type="text/javascript">
    
    alert("Browser"+"\n\n"+navigator.appName);
    
    student = confirm("Are you student at Silicon ?");
    
    if(student==true){
    alert("please enter your marks");
    }
    else{
    alert("please register first");
    location.href="Registration.html";
    }
    
    function getGrade(){
    
    if((Number(document.form1.input1.value)>90) && (Number(document.form1.input1.value)<100))
    {
    alert("Grade A");
    }
    
    else if((Number(document.form1.input1.value)>80) && (Number(document.form1.input1.value)<90))
    {
    alert("Grade B");
    }
    
    else if((Number(document.form1.input1.value)>70) && (Number(document.form1.input1.value)<80))
    {
    alert("Grade C");
    }
    
    else if((Number(document.form1.input1.value)>60) && (Number(document.form1.input1.value)<70))
    {
    alert("Grade D");
    }
    
    else if((Number(document.form1.input1.value)>50) && (Number(document.form1.input1.value)<60))
    {
    alert("Grade F");
    }
    
    else if(Number(document.form1.input1.value)<50)
    {
    alert("Grade G");
    }
    }
    
    function identifyKey(evt){
    evt = evt || window.event;
    if(navigator.appName==/*Internet Explorer*/){
    var charCode = evt.keyCode;
    }
    else{
    var charCode = evt.which;
    }
    alert(charCode);
    }
    
    </script>
    <style type="text/css">
    
    #main{
    
    margin:auto;
    width:70%;
    }
    
    #top{
    font-size:20px;
    font-weight:bolder;
    color:#007700;
    text-decoration:underline;
    }
    
    #s1{
    font-size:20px;
    font-weight:bold;
    color:#7700ff;
    }
    
    #s2{
    font-size:20px;
    font-weight:bold;
    color:#00ff00;
    }
    
    #s3{
    font-size:20px;
    font-weight:bold;
    color:#ff0000;
    }
    
    #form1{
    width:600px;
    height:80px;
    padding:20px;
    background-color:#aaaaaa;
    }
    </style>
    </head>
    
    <body>
    <div id="main">
    <p id="top">Assignment 4 - JavaScript Conditional Variables</p>
    <span id=s1>This is Form for checking Grade</span>
    
    <form id=form1 name=form1>
    <table>
    <tr><td>Enter Marks </td><td>: <input type="text" name="input1" onkeypress=identifyKey(event) /></td></tr>
    
    <tr><td><input type="button" name=btn1 value="Get Grade" onclick=getGrade() /></td></tr>
    
    </table>
    </form>
    </div>
    </body>
    </html>
    When I try to check whats wrong with this script in Firebug, I get error
    No Javascript on this page

    If <script> tags have a "type" attribute it should equal "text/javascript" or "application/javascript"
    Why am I getting such an error in Firebug. I understand there is some syntax error in this script How can I check whats wrong if I am getting such a message in Firebug ?

    Thanks

  2. #2
    Join Date
    Jan 2011
    Posts
    117
    your corrected code

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
    <title>Assignment 4 - JavaScript Conditional Variables</title>
    <head>
    <script type="text/javascript">
    
    alert("Browser"+"\n\n"+navigator.appName);
    
    student = confirm("Are you student at Silicon ?");
    
    if(student==true){
    alert("please enter your marks");
    }
    else{
    alert("please register first");
    location.href="Registration.html";
    }
    
    function getGrade(){
    
    if((Number(document.form1.input1.value)>90) && (Number(document.form1.input1.value)<100))
    {
    alert("Grade A");
    }
    
    else if((Number(document.form1.input1.value)>80) && (Number(document.form1.input1.value)<90))
    {
    alert("Grade B");
    }
    
    else if((Number(document.form1.input1.value)>70) && (Number(document.form1.input1.value)<80))
    {
    alert("Grade C");
    }
    
    else if((Number(document.form1.input1.value)>60) && (Number(document.form1.input1.value)<70))
    {
    alert("Grade D");
    }
    
    else if((Number(document.form1.input1.value)>50) && (Number(document.form1.input1.value)<60))
    {
    alert("Grade F");
    }
    
    else if(Number(document.form1.input1.value)<50)
    {
    alert("Grade G");
    }
    }
    
    function identifyKey(evt){
    evt = evt || window.event;
    if(navigator.appName=="Internet Explorer"){
    var charCode = evt.keyCode;
    }
    else{
    var charCode = evt.which;
    }
    alert(charCode);
    }
    
    </script>
    <style type="text/css">
    
    #main{
    
    margin:auto;
    width:70&#37;;
    }
    
    #top{
    font-size:20px;
    font-weight:bolder;
    color:#007700;
    text-decoration:underline;
    }
    
    #s1{
    font-size:20px;
    font-weight:bold;
    color:#7700ff;
    }
    
    #s2{
    font-size:20px;
    font-weight:bold;
    color:#00ff00;
    }
    
    #s3{
    font-size:20px;
    font-weight:bold;
    color:#ff0000;
    }
    
    #form1{
    width:600px;
    height:80px;
    padding:20px;
    background-color:#aaaaaa;
    }
    </style>
    </head>
    
    <body>
    <div id="main">
    <p id="top">Assignment 4 - JavaScript Conditional Variables</p>
    <span id=s1>This is Form for checking Grade</span>
    
    <form id=form1 name=form1>
    <table>
    <tr><td>Enter Marks </td><td>: <input type="text" name="input1" onkeypress="identifyKey(event)" /></td></tr>
    
    <tr><td><input type="button" name=btn1 value="Get Grade" onclick="getGrade()" /></td></tr>
    
    </table>
    </form>
    </div>
    </body>
    </html>

  3. #3
    Join Date
    Apr 2008
    Posts
    84
    Thanks for correcting code.

    Actually answer I am looking for is, why is FireBug gioving such an error ? I am expecting firebug to point to the line where error lies or provide description of error.

    This means , if code is right then firebug will display it (which is not needed) and if there is error in code, firebug will not display entire javascript.

    How can I use FireBug to debug an error in JavaScript ?

    Thanks

  4. #4
    Join Date
    Nov 2010
    Posts
    1,036
    try clicking on the console tab in firebug. you will see this error:
    syntax error
    if (navigator.appName==/*Internet Explorer*/){

    (line 55, col 44)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles