Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uncaught typeerror undefined is not a function in javascript

The following function sets the following error: "uncaught typeerror undefined is not a function javascript" worked fine before , now fails =( Helpme please!

$('longitud-grados').addEvent('change', function(event){
        var lg = $('longitud-grados').value;
        var lm = $('longitud-minutos').value;
        var ls = $('longitud-segundos').value;

        if((lg > 117) || (lg < 86)) $('longitud-grados').value = '';

        if(lg != '' && lm != '' && ls != ''){
            c = new Coordenada();
            l = c.gms2dec(lg, lm, ls, 'w');
            $('longitud').value = l.decimal;
        }
    });
like image 895
Luigi Avatar asked Jul 23 '26 14:07

Luigi


1 Answers

this is because $ is not defined. I had a look at your web page

> $('longitud-grados').
Uncaught SyntaxError: Unexpected token } VM1196:732
> $('longitud-grados')
Uncaught TypeError: undefined is not a function VM1555:2
> $
undefined
> MooTools
Object {version: "1.4.5", build: "ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0", More: Object, lang: Object}
> document.id
function (D,F,E){if(D&&D.$family&&D.uniqueNumber){return D;}var l=typeOf(D);return(e[l])?e[l](D,F,E||document):null;} 

So, for whatever reason, your $ is not defined - either do $ = document.id; or change your script to use document.id('longitud-grados');

you can also use a closure pattern around that code like

(function($){
    ...
    $('someid'); // will work
}(document.id));

keep in mind you also have jQuery on the page, doing $ = document.id may cause problems with your jQuery scripts if it's not using .noConflict() mode

like image 74
Dimitar Christoff Avatar answered Jul 26 '26 05:07

Dimitar Christoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!