Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:15:29+00:00 2026-05-30T20:15:29+00:00

I know java script doesn’t have call by reference. So how can I solve

  • 0

I know java script doesn’t have call by reference. So how can I solve this?

(function($){

$.fn.extend({

    something: function(options) {
        var Status;
        var defaults = {
            regex:/^([\u0600-\u06FF]|\s)*$/,
            errortxt:"Invalid input",
            emptytxt:"It should not be empty"
        }
        var options =  $.extend(defaults, options);
        $(this).bind('change', function () { 
            Status = true;
             $(this).each(function() {
                /*variables*/
                var necessaryElement;
                if (options.regex && options.errortxt && options.errorsection)
                {
                    var filter = options.regex;
                    var $this = $(this);
                    var wrongMessage = options.errortxt;
                    var $errordiv = $("[ID$="+options.errorsection+"]");
                } else{ 
                    console.log("Error : Not enough arguments for invoking something Plugin");
                }
                if (options.emptytxt)
                {
                    var noMessage = options.emptytxt;
                    necessaryElement = true;
                }
                else
                {
                    necessaryElement = false;
                }
                var elementvalue = $this.val();

                /* Methods */
                if (elementvalue != "" && necessaryElement) {
                    if (filter.test(elementvalue)){
                        $this.removeClass("error").addClass("ok");
                        $errordiv.fadeOut(300);
                    } else {
                        Status = false;
                        $this.removeClass("ok").addClass("error");
                        $errordiv.fadeIn(200);
                        $errordiv.text(wrongMessage);
                    }
                } else if (elementvalue == "" && necessaryElement) {
                    Status = false;
                    $this.removeClass("ok").addClass("error");
                    $errordiv.fadeIn(200);
                    $errordiv.text(noMessage);
                }
            });
        });
        return Status;
    }
});
})(jQuery);

and I call it in another js in this way:

var myarray=new Array();
myarray[0] = $('#selector').something({
regex:/^([\u0600-\u06FF]|\s)*$/,
// another options
});
$('#selector').change(function (){
    alert (myarray[0]);
});

but it alerts undefined.

If I change var Status to var Status= true Then it always alerts true.

Can anyone help me? How I can change the code to return the desired Status?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:15:31+00:00Added an answer on May 30, 2026 at 8:15 pm

    Edit : Trying to be clearer.

    Something() returns a value which is modified by change.
    So when you call something you return the value unmodified.
    Then you call change that will change the value, but it’s not passed by reference in the array so it won’t change anything.

    You may want to use the data function available on JQuery objects for keeping data.
    Here is a simplified version:

    (function($){
        $.fn.extend({
    
        something: function(options) {
    
            $(this).bind('change', function () {
                $(this).data('status','true');
            });
        }
    });
    })(jQuery);
    
    $(document).ready(function() {
        var myarray=new Array();
        myarray[0] = $('#selector').something({
        regex:/^([\u0600-\u06FF]|\s)*$/
        });
        $('#selector').change(function (){
            alert ($(this).data('status'));
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if I can pass data from flash (action script) to java
I know that javascript doesn't have pointers in terms of a variable referring to
I have built a horizontal scrolling website. I don't really know much about Java
We have an existing java-based heavyweight project that needed an interactive script interpreter. After
My Ant script won't compile code. It says it doesn't find a C:\Program Files\Java\jdk1.6.0_25.
I have a shell script that calls a java jar file and runs an
Does anyone know how to do something like this. Lets say I generate on
I have a DOS batch script that invokes a java application which interacts with
I have this following java code skeleton - try { Question q = null;
I am trying to compare two decimal values in Java script. I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.