0

I've been using this code to move ImageId to jCrop

But _ImageId variable is given by reference.

How can I give _ImageId variable to the jCrop by value?

    var _ImageId = 0;

    $(document).ready(
    function(){    
        $('.page .image').attr("id", function(){  
        _ImageId = $(this).attr("id");
        return $(this).attr("id");
    }).Jcrop({
        ImageId : _ImageId,  // my problem is here , when _ImageId change , all of them will change 
        onSelect: Page_ImageSelected
    });      
}
Pankit Kapadia
  • 1,579
  • 13
  • 25
Ata
  • 12,126
  • 19
  • 63
  • 97

2 Answers2

1

Your code is a little ... "weird".

Maybe you should try something like that :

$(document).ready(function() {
    $('.page .image').each(function() {
        var element = $(this);
        element.Jcrop({
            ImageId : element.attr('id'),
            onSelect: Page_ImageSelected
        });
    });
}​);​

Javascript use a "by value" call when you are using "simple" types like number, integer, float, string, boolean ...

The problem here is your code.

Magus
  • 14,796
  • 3
  • 36
  • 51
  • even I think your code should works , but it do not work anyway , evern It do not run until var element = $(this); – Ata Dec 21 '12 at 11:34
  • So maybe your selector `.page .image` is wrong. But i can't tell without your html code. – Magus Dec 21 '12 at 11:36
0

You already do pass the _ImageId by value, the JCrop method will receive an object whose ImageId property is 0 (or the value assigned in the attr callback) and will not change when _ImageId is changed.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • When do it change, what do you think changes it? Of course the property might change, but not from assignments to `_ImageId` – Bergi Dec 21 '12 at 11:52