Function Not Defined Javascript Error in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nightshade
    New Member
    • Mar 2006
    • 4

    Function Not Defined Javascript Error in Firefox

    I have an HTML form using JavaScript that seems to function properly in IE but not in Mozilla Firefox 1.5 or in Netscape 8.1 (based on Firefox). The error in Firefox/Netscape is "testForIt( ) not defined."

    Following is the JavaScript code:

    Code:
    <script language="JScript">
      <!--
      var request = false;
      var useImage = false;
      var useFrame = false;
      var inqnum, compname = 0;
    
      alert ('Java');
    
      if (document.images) useImage = true;
      else if (navigator.appVersion.indexOf('MSIE 3') > -1) useFrame = true;
    
      function cleaninquirynumber(aValue)
        {
        var aResult = '';
        var sValidChar = '0123456789';
        for (n=0;n<=aValue.length;n++) {
          if (sValidChar.indexOf(aValue.charAt(n)) != -1)
            {
            if (n == aValue.length - 4)
            aResult = aResult.concat('-');
            aResult = aResult.concat(aValue.charAt(n));
            }
          }
        return(aResult);
        }
    
      function cleancompanyname(aValue)
        {
        var aResult = '';
        var sValidChar2 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        aValue = aValue.toUpperCase();
      	bResult = 1;
        for (n=0;(aResult.length<=(Math.min(aValue.length,4))) && bResult;n++) {
          if (n > aValue.length) bResult = 0;
          if (sValidChar2.indexOf( aValue.charAt(n)) != -1)
            {
            aResult = aResult.concat(aValue.charAt(n));
            }
          }
        return(aResult);
        }
    
      function testForIt() {
          alert ('TestForIt.');
          if ((document.getElementsByName('inqnum').value != '') && (document.getElementsByName('compname').value != '')) {
    	  alert ('if Document');
              if (useImage) {
                  request = true;
                  document.images["testImage"].src = cleaninquirynumber(document.getElementsByName('inqnum').value)+cleancompanyname(document.getElementsByName('compname').value) + '.gif';
                  alert ('if (useimage)');
              }
              else if (useFrame)
                  document.frames[0].location.href = 'e' + cleaninquirynumber(document.getElementsByName('inqnum').value)+cleancompanyname(document.getElementsByName('compname').value) + '.htm';
              else {
    	      alert ('Test-Load');
                  request = true;
                  loadIt();
              }
          }
          return false;
      }
    
      function loadIt() {
          if (request)
          {
            document.logon.action = 'inq'+cleaninquirynumber(document.getElementsByName('inqnum').value)+cleancompanyname(document.getElementsByName('compname').value)+'.htm';
            document.logon.submit();
          }
          request = false;
    
      }
    
      function failIt() {
          request = false;
          if (useImage)
            {
          document.images["testImage"].src = 'blank.gif';
          }
        document.logon.action = 'nocompanyinquiries.htm';
        document.logon.submit();
      }
    
    
    
    if (useImage)
        document.write('<IMG SRC="blank.gif" NAME="testImage" ALT="." WIDTH="1" HEIGHT="1" onLoad="loadIt()" onError="failIt()">');
    else if (useFrame)
        document.write('<IFRAME FRAMEBORDER="0" WIDTH="1" HEIGHT="1" MARGINHEIGHT="0" MARGINWIDTH="0" SRC="blank.htm"><\/IFRAME>');
    //-->
    </script>
    And here is the HTML code that calls it:



    Code:
        <FORM NAME="logon" action="nocompanyinquiries.htm"></FORM>
        <table align=center><tr><td>Inquiry Number:</td><td><input type="text" name="inqnum" size="10" maxlength="10"></td></tr>
        <tr><td>Company Name:</td><td><input type="text" name="compname" size="30"></td></tr>
        <tr><td>&nbsp;</td><td><input type="submit" value="Go" onClick="testForIt()"></td></tr>
        </table>
    Any ideas or suggestions would be greatly appreciated. Thank you all in advance.
  • Nightshade
    New Member
    • Mar 2006
    • 4

    #2
    Function Not Defined Javascript Error in Firefox

    I have an HTML form using JavaScript that seems to function properly in IE but not in Mozilla Firefox 1.5 or in Netscape 8.1 (based on Firefox). The error in Firefox/Netscape is "testForIt( ) not defined."

    Following is the JavaScript code:

    Code:
    <script language="JScript">
    <!--
    var request = false;
    var useImage = false;
    var useFrame = false;
    var inqnum, compname = 0;
    
    alert ('Java');
    
    if (document.images) useImage = true;
    else if (navigator.appVersion.indexOf('MSIE 3') > -1) useFrame = true;
    
    function cleaninquirynumber(aValue)
    {
    var aResult = '';
    var sValidChar = '0123456789';
    for (n=0;n<=aValue.length;n++) {
    if (sValidChar.indexOf(aValue.charAt(n)) != -1)
    {
    if (n == aValue.length - 4)
    aResult = aResult.concat('-');
    aResult = aResult.concat(aValue.charAt(n));
    }
    }
    return(aResult);
    }
    
    function cleancompanyname(aValue)
    {
    var aResult = '';
    var sValidChar2 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    aValue = aValue.toUpperCase();
    bResult = 1;
    for (n=0;(aResult.length<=(Math.min(aValue.length,4))) && bResult;n++) {
    if (n > aValue.length) bResult = 0;
    if (sValidChar2.indexOf( aValue.charAt(n)) != -1)
    {
    aResult = aResult.concat(aValue.charAt(n));
    }
    }
    return(aResult);
    }
    
    function testForIt() {
    alert ('TestForIt.');
    if ((document.getElementsByName('inqnum').value != '') && (document.getElementsByName('compname').value != '')) {
    alert ('if Document');
    if (useImage) {
    request = true;
    document.images["testImage"].src = cleaninquirynumber(document.getElementsByName('inq num').value)+cleancompanyname(document.getElements ByName('compname').value) + '.gif';
    alert ('if (useimage)');
    }
    else if (useFrame)
    document.frames[0].location.href = 'e' + cleaninquirynumber(document.getElementsByName('inq num').value)+cleancompanyname(document.getElements ByName('compname').value) + '.htm';
    else {
    alert ('Test-Load');
    request = true;
    loadIt();
    }
    }
    return false;
    }
    
    function loadIt() {
    if (request)
    {
    document.logon.action = 'inq'+cleaninquirynumber(document.getElementsByNam e('inqnum').value)+cleancompanyname(document.getEl ementsByName('compname').value)+'.htm';
    document.logon.submit();
    }
    request = false;
    
    }
    
    function failIt() {
    request = false;
    if (useImage)
    {
    document.images["testImage"].src = 'blank.gif';
    }
    document.logon.action = 'nocompanyinquiries.htm';
    document.logon.submit();
    }
    
    
    
    if (useImage)
    document.write('<IMG SRC="blank.gif" NAME="testImage" ALT="." WIDTH="1" HEIGHT="1" onLoad="loadIt()" onError="failIt()">');
    else if (useFrame)
    document.write('<IFRAME FRAMEBORDER="0" WIDTH="1" HEIGHT="1" MARGINHEIGHT="0" MARGINWIDTH="0" SRC="blank.htm"><\/IFRAME>');
    //-->
    </script>

    And here is the HTML code that calls it:



    Code:
    <FORM NAME="logon" action="nocompanyinquiries.htm"></FORM>
    <table align=center><tr><td>Inquiry Number:</td><td><input type="text" name="inqnum" size="10" maxlength="10"></td></tr>
    <tr><td>Company Name:</td><td><input type="text" name="compname" size="30"></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Go" onClick="testForIt()"></td></tr>
    </table>

    Any ideas or suggestions would be greatly appreciated. Thank you all in advance.

    Comment

    • Nightshade
      New Member
      • Mar 2006
      • 4

      #3
      By the way...

      Incidentally the alerts were just something I there in for testing purposes.

      Comment

      • Nightshade
        New Member
        • Mar 2006
        • 4

        #4
        Found it.

        Nevermind, I think I found it. I inherited the code and just noticed that the original programmer had specified JScript rather than Javascript as the script language.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Yes, that would cause problems. In fact, the language attribute is deprecated and should be replaced with the type attribute:
          Code:
          <script type="text/javascript">

          Comment

          • buzznode
            New Member
            • Feb 2010
            • 1

            #6
            Using FF I just stumbled upon the 'JavaScript' versus 'text/javascript' error for a JS script that wasn't loading. Keep in mind that all the other 20+ scripts for the site had 'JavaScript' for the type, but the latest one I created would not load until I made it's type = 'text/javascript'.

            Can someone say GAY?!?!?!

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Was that type or language?

              If you're going to use non-standard or deprecated attributes, expect things not to work.

              Comment

              Working...