SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery how to access variable from outside plugin

    I got a simple plugin as below:

    Code JavaScript:
    $.fn.ajaxSubmit = function(options){
        var submisable = true;
    }

    I want to to able to access the variable submisable from outside the plugin like doing something like below:

    Code JavaScript:
    $(function(){
        $('form').ajaxSubmit();
        $('div').click(function(){
            submisable =false;
        });
    });

    How can I do that?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Because the click function runs as a global function, you need to store the value so that it's globally accessible.

    You can use the data method to store and retrieve values on page elements. Since it's relating to whether the form is submissible, the form itself would be a good element in which to store the data.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figure out something intersting, I access variable by doing this

    Code JavaScript:
    $.fn.ajaxSubmit = function(options){
        var submisable = false;
    	var $this = $(this);
    	$this.children('div').change(function(){
    		submisable = true;
    	});
    	$.fn.ajaxSubmit.changevar = function(){
    		$this.children('div').change();
    	}
    }

    call

    Code JavaScript:
    $.fn.ajaxSubmit.changevar();// now var submisable changed to true


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •