Monday, 15 August 2011

javascript - Uncaught TypeError: undefined is not a function -



javascript - Uncaught TypeError: undefined is not a function -

i newbie js, have copied script jqueryui.com dialog widget , pasted in yii project, got error: uncaught typeerror: undefined not function, function of $( "#dialog-form" ).dialog, error, , how can prepare it, here code:

$(function() { var name = $( "#name" ), email = $( "#email" ), password = $( "#password" ), allfields = $( [] ).add( name ).add( email ).add( password ), tips = $( ".validatetips" ); function updatetips( t ) { tips .text( t ) .addclass( "ui-state-highlight" ); settimeout(function() { tips.removeclass( "ui-state-highlight", 1500 ); }, 500 ); } function checklength( o, n, min, max ) { if ( o.val().length > max || o.val().length < min ) { o.addclass( "ui-state-error" ); updatetips( "length of " + n + " must between " + min + " , " + max + "." ); homecoming false; } else { homecoming true; } } function checkregexp( o, regexp, n ) { if ( !( regexp.test( o.val() ) ) ) { o.addclass( "ui-state-error" ); updatetips( n ); homecoming false; } else { homecoming true; } } $( "#dialog-form" ).dialog({ autoopen: false, height: 300, width: 350, modal: true, buttons: { "create account": function() { var bvalid = true; allfields.removeclass( "ui-state-error" ); bvalid = bvalid && checklength( name, "username", 3, 16 ); bvalid = bvalid && checklength( email, "email", 6, 80 ); bvalid = bvalid && checklength( password, "password", 5, 16 ); bvalid = bvalid && checkregexp( name, /^[a-z]([0-9a-z_])+$/i, "username may consist of a-z, 0-9, underscores, begin letter." ); // jquery.validate.js (by joern), contributed scott gonzalez: http://projects.scottsplayground.com/email_address_validation/ bvalid = bvalid && checkregexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.)+(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.?$/i, "eg. ui@jquery.com" ); bvalid = bvalid && checkregexp( password, /^([0-9a-za-z])+$/, "password field allow : a-z 0-9" ); if ( bvalid ) { $( "#users tbody" ).append( "<tr>" + "<td>" + name.val() + "</td>" + "<td>" + email.val() + "</td>" + "<td>" + password.val() + "</td>" + "</tr>" ); $( ).dialog( "close" ); } }, cancel: function() { $( ).dialog( "close" ); } }, close: function() { allfields.val( "" ).removeclass( "ui-state-error" ); } }); $( "#create-user" ) .button() .click(function() { $( "#dialog-form" ).dialog( "open" ); }); });

did include like

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>

javascript jquery jquery-ui yii

1 comment:

  1. This is a common JavaScript error that happens when you try to call a function before it is defined. You get "'undefined' is not a function" error when you try to execute a function that is uninitialized or improperly initialized . It means that the expression did not return a function object. So you have to figure out what you are trying to execute isn't a function.

    In Javascript , when you execute a function, it's evaluated like the following:

    expression.that('returns').aFunctionObject(); // js
    execute -> expression.that('returns').aFunctionObject // what the JS engine does

    That expression may be complex. So when you get undefined is not a function it means that expression did not return a function object. So you have to figure out what you are trying to execute isn't a function.

    ReplyDelete