By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

Function Not Defined Javascript Error in Firefox

P: 4
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:

Expand|Select|Wrap|Line Numbers
  1. <script language="JScript">
  2.   <!--
  3.   var request = false;
  4.   var useImage = false;
  5.   var useFrame = false;
  6.   var inqnum, compname = 0;
  7.  
  8.   alert ('Java');
  9.  
  10.   if (document.images) useImage = true;
  11.   else if (navigator.appVersion.indexOf('MSIE 3') > -1) useFrame = true;
  12.  
  13.   function cleaninquirynumber(aValue)
  14.     {
  15.     var aResult = '';
  16.     var sValidChar = '0123456789';
  17.     for (n=0;n<=aValue.length;n++) {
  18.       if (sValidChar.indexOf(aValue.charAt(n)) != -1)
  19.         {
  20.         if (n == aValue.length - 4)
  21.         aResult = aResult.concat('-');
  22.         aResult = aResult.concat(aValue.charAt(n));
  23.         }
  24.       }
  25.     return(aResult);
  26.     }
  27.  
  28.   function cleancompanyname(aValue)
  29.     {
  30.     var aResult = '';
  31.     var sValidChar2 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  32.     aValue = aValue.toUpperCase();
  33.       bResult = 1;
  34.     for (n=0;(aResult.length<=(Math.min(aValue.length,4))) && bResult;n++) {
  35.       if (n > aValue.length) bResult = 0;
  36.       if (sValidChar2.indexOf( aValue.charAt(n)) != -1)
  37.         {
  38.         aResult = aResult.concat(aValue.charAt(n));
  39.         }
  40.       }
  41.     return(aResult);
  42.     }
  43.  
  44.   function testForIt() {
  45.       alert ('TestForIt.');
  46.       if ((document.getElementsByName('inqnum').value != '') && (document.getElementsByName('compname').value != '')) {
  47.       alert ('if Document');
  48.           if (useImage) {
  49.               request = true;
  50.               document.images["testImage"].src = cleaninquirynumber(document.getElementsByName('inqnum').value)+cleancompanyname(document.getElementsByName('compname').value) + '.gif';
  51.               alert ('if (useimage)');
  52.           }
  53.           else if (useFrame)
  54.               document.frames[0].location.href = 'e' + cleaninquirynumber(document.getElementsByName('inqnum').value)+cleancompanyname(document.getElementsByName('compname').value) + '.htm';
  55.           else {
  56.           alert ('Test-Load');
  57.               request = true;
  58.               loadIt();
  59.           }
  60.       }
  61.       return false;
  62.   }
  63.  
  64.   function loadIt() {
  65.       if (request)
  66.       {
  67.         document.logon.action = 'inq'+cleaninquirynumber(document.getElementsByName('inqnum').value)+cleancompanyname(document.getElementsByName('compname').value)+'.htm';
  68.         document.logon.submit();
  69.       }
  70.       request = false;
  71.  
  72.   }
  73.  
  74.   function failIt() {
  75.       request = false;
  76.       if (useImage)
  77.         {
  78.       document.images["testImage"].src = 'blank.gif';
  79.       }
  80.     document.logon.action = 'nocompanyinquiries.htm';
  81.     document.logon.submit();
  82.   }
  83.  
  84.  
  85.  
  86. if (useImage)
  87.     document.write('<IMG SRC="blank.gif" NAME="testImage" ALT="." WIDTH="1" HEIGHT="1" onLoad="loadIt()" onError="failIt()">');
  88. else if (useFrame)
  89.     document.write('<IFRAME FRAMEBORDER="0" WIDTH="1" HEIGHT="1" MARGINHEIGHT="0" MARGINWIDTH="0" SRC="blank.htm"><\/IFRAME>');
  90. //-->
  91. </script>
  92.  
  93.  
  94.  
And here is the HTML code that calls it:



Expand|Select|Wrap|Line Numbers
  1.     <FORM NAME="logon" action="nocompanyinquiries.htm"></FORM>
  2.     <table align=center><tr><td>Inquiry Number:</td><td><input type="text" name="inqnum" size="10" maxlength="10"></td></tr>
  3.     <tr><td>Company Name:</td><td><input type="text" name="compname" size="30"></td></tr>
  4.     <tr><td>&nbsp;</td><td><input type="submit" value="Go" onClick="testForIt()"></td></tr>
  5.     </table>
  6.  
Any ideas or suggestions would be greatly appreciated. Thank you all in advance.
Mar 16 '06 #1
Share this Question
Share on Google+
6 Replies


P: 4
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:

Expand|Select|Wrap|Line Numbers
  1. <script language="JScript">
  2. <!--
  3. var request = false;
  4. var useImage = false;
  5. var useFrame = false;
  6. var inqnum, compname = 0;
  7.  
  8. alert ('Java');
  9.  
  10. if (document.images) useImage = true;
  11. else if (navigator.appVersion.indexOf('MSIE 3') > -1) useFrame = true;
  12.  
  13. function cleaninquirynumber(aValue)
  14. {
  15. var aResult = '';
  16. var sValidChar = '0123456789';
  17. for (n=0;n<=aValue.length;n++) {
  18. if (sValidChar.indexOf(aValue.charAt(n)) != -1)
  19. {
  20. if (n == aValue.length - 4)
  21. aResult = aResult.concat('-');
  22. aResult = aResult.concat(aValue.charAt(n));
  23. }
  24. }
  25. return(aResult);
  26. }
  27.  
  28. function cleancompanyname(aValue)
  29. {
  30. var aResult = '';
  31. var sValidChar2 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  32. aValue = aValue.toUpperCase();
  33. bResult = 1;
  34. for (n=0;(aResult.length<=(Math.min(aValue.length,4))) && bResult;n++) {
  35. if (n > aValue.length) bResult = 0;
  36. if (sValidChar2.indexOf( aValue.charAt(n)) != -1)
  37. {
  38. aResult = aResult.concat(aValue.charAt(n));
  39. }
  40. }
  41. return(aResult);
  42. }
  43.  
  44. function testForIt() {
  45. alert ('TestForIt.');
  46. if ((document.getElementsByName('inqnum').value != '') && (document.getElementsByName('compname').value != '')) {
  47. alert ('if Document');
  48. if (useImage) {
  49. request = true;
  50. document.images["testImage"].src = cleaninquirynumber(document.getElementsByName('inq num').value)+cleancompanyname(document.getElements ByName('compname').value) + '.gif';
  51. alert ('if (useimage)');
  52. }
  53. else if (useFrame)
  54. document.frames[0].location.href = 'e' + cleaninquirynumber(document.getElementsByName('inq num').value)+cleancompanyname(document.getElements ByName('compname').value) + '.htm';
  55. else {
  56. alert ('Test-Load');
  57. request = true;
  58. loadIt();
  59. }
  60. }
  61. return false;
  62. }
  63.  
  64. function loadIt() {
  65. if (request)
  66. {
  67. document.logon.action = 'inq'+cleaninquirynumber(document.getElementsByNam e('inqnum').value)+cleancompanyname(document.getEl ementsByName('compname').value)+'.htm';
  68. document.logon.submit();
  69. }
  70. request = false;
  71.  
  72. }
  73.  
  74. function failIt() {
  75. request = false;
  76. if (useImage)
  77. {
  78. document.images["testImage"].src = 'blank.gif';
  79. }
  80. document.logon.action = 'nocompanyinquiries.htm';
  81. document.logon.submit();
  82. }
  83.  
  84.  
  85.  
  86. if (useImage)
  87. document.write('<IMG SRC="blank.gif" NAME="testImage" ALT="." WIDTH="1" HEIGHT="1" onLoad="loadIt()" onError="failIt()">');
  88. else if (useFrame)
  89. document.write('<IFRAME FRAMEBORDER="0" WIDTH="1" HEIGHT="1" MARGINHEIGHT="0" MARGINWIDTH="0" SRC="blank.htm"><\/IFRAME>');
  90. //-->
  91. </script>
  92.  

And here is the HTML code that calls it:



Expand|Select|Wrap|Line Numbers
  1. <FORM NAME="logon" action="nocompanyinquiries.htm"></FORM>
  2. <table align=center><tr><td>Inquiry Number:</td><td><input type="text" name="inqnum" size="10" maxlength="10"></td></tr>
  3. <tr><td>Company Name:</td><td><input type="text" name="compname" size="30"></td></tr>
  4. <tr><td>&nbsp;</td><td><input type="submit" value="Go" onClick="testForIt()"></td></tr>
  5. </table>

Any ideas or suggestions would be greatly appreciated. Thank you all in advance.
Mar 16 '06 #2

P: 4
Incidentally the alerts were just something I there in for testing purposes.
Mar 16 '06 #3

P: 4
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.
Mar 16 '06 #4

acoder
Expert Mod 15k+
P: 16,027
Yes, that would cause problems. In fact, the language attribute is deprecated and should be replaced with the type attribute:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
Jun 21 '08 #5

P: 1
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?!?!?!
Feb 6 '10 #6

acoder
Expert Mod 15k+
P: 16,027
Was that type or language?

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

Post your reply

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