Reputation: 19380
I have small bug (I suppose) in my Javascript file. It is simple file but it is not working as expected on Firefox 6 (on Chrome it is working fine). Everything is working except submit(), and validate() is working only when called within document.ready, if I try to access these functions directly, I get...
uncaught exception: ReferenceError: (function) is not defined
Here is the JS file http://pastebin.com/raw.php?i=CMy4WYPF, it is loaded after jQuery lib, there are no other JS files.
Thank you very much for your help.
Upvotes: 0
Views: 8003
Reputation: 1176
Dont forget to include ,
<script src="jquery-1.xx.x.min.js" type="text/javascript"> </script>
if you are using jquery, xx-x stand for the
Upvotes: 0
Reputation: 147413
You don't show how or when the code is loaded, so when it is executed is unknown.
The document markup is not provided so it is impossible to tell what may or may not work, or why. Here are some suggestions for improvements, they may or may not make any difference.
The following statements:
> var exception = $('#teligence-exception');
> var form = $('#teligence-ctc form');
are at the top of the script. Do the elements referenced by the IDs exist in the DOM when the statements are executed?
Searching for codes in an array using jQuery's inArray is inefficient in browsers that lack a native Array.prototype.indexOf method (which is quite a few). Far better to have codes as a string with a delimiter and use the ubiquitous String.prototype.indexOf() method, e.g.
var codes = '|201|202|203|';
...
var x = code.indexOf('|' + val + '|');
The submit function is not called in the posted code.
Much of the script appears very inefficient:
> var val = $(this).val();
> $(this).val( val.replace(/[^0-9]/, '') );
can be
var val = this.value;
this.value = val.replace(/D/g, '');
note that in the original code, only the first non-digit character will be replaced. In the suggested code, all non-digit characters will be replaced (courtesy of the g flag).
Also:
validate($(this).attr('name'));
can be:
validate(this.value);
And so on. The idea is to not create unnecessary jQuery objects.
Upvotes: 3