1

The error is:

ReferenceError: $portal is not defined $portal.user = {

i am writing whole new thing with Jquery and normal javascript.(this is my first web project still learning.)

I am trying to execute $portal.user.init() function from Jquery document ready function, it is not executing.

I may be missing something, could any one please help, how i should call above method from Jquery & concept behind it.

here is my jQuery code

<script type="text/javascript">
            $( document ).ready(function() {
                // Initiate portal.. 
                $portal.user.init(<?php echo $_SESSION['user_id']; ?>,
                        "<?php echo $_SESSION['user_name']; ?>",
                        "<?php echo $_SESSION['acc_type']; ?>",
                        "<?php echo $_SESSION['lang']; ?>",
                        "<?php echo $_SESSION['first_name']; ?>",
                        "<?php echo $_SESSION['last_name']; ?>",
                        "<?php echo $_SESSION['picture']; ?>",
                        "<?php echo $_SESSION['email']; ?>"
                        );
            });

And i created another javascript file say myweb.js code is like this

var _no_profile_pic = "../img/no_profile_pic.png";

/* 
 * Class    :   $portal.user
 * Desc     :   Portal User Related Functions
 */
$portal.user = {
    user_id: 0,
    user_name: '',
    acc_type: '',
    lang: '',
    first_name: '',
    last_name: '',
    picture: '',
    email: '',
    /*
     * $portal.user.init : Initilise user
     * Params   :
     *      user_id - user id
     *      user_name - login user name
     *      acc_type - Type of user account like (A - Admin, V - Verified, U - Unverified, D - Deleted)
     *      lang - User Language like (en-english)
     *      first_name - User First Name
     *      last_name - User Last Name
     *      picture - User Picture URL
     *      email - User Email Address
     * Returns  : None
     */
    init: function(user_id, user_name, acc_type, lang, first_name, last_name, picture, email)
    {
        $portal.user.user_id = user_id;
        $portal.user.user_name = user_name;
        $portal.user.acc_type = acc_type;
        $portal.user.lang = lang;
        $portal.user.first_name = first_name;
        $portal.user.last_name = last_name;
        $portal.user.picture = (picture == indef || picture == '' ? _no_profile_pic : picture);
        $portal.user.email = email;
        alert(this.user_id);
    }
};
3
  • 1
    Could you check your console for any errors and also whether jquery lib is loaded ? Commented May 23, 2014 at 13:55
  • Whats indef? -> picture == indef - For undefined or empty you can .picture = picture || _no_profile_pic, (That glob is probably better put within the class as well) Commented May 23, 2014 at 13:59
  • it gives error in console - ReferenceError: $portal is not defined $portal.user = { Commented May 23, 2014 at 14:17

1 Answer 1

0

You must first define $portal as an object, before you try to set its properties by adding the user object.

$portal = {}; // define $portal as an object

// now the user object can be added
$portal.user = {
    ...
    ...
};
Sign up to request clarification or add additional context in comments.

1 Comment

Great @MrCode, you are great...thank you so much form your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.