wrong object at event

wrong object at event

In my script jQuery creates 15 fields in a loop resulting in:
  1. ...
  2. <div  id="field_3" ...></div>
  3. <div  id="field_4" ...></div>
  4. ...
This all works fine. Then I try to bind events to them. When done manualy like this:
  1. var index = 3
  2. $(document).on("click", "#veld_" + index, function(){ alert( index ) });
  3. index = 4
  4. $(document).on("click", "#veld_" + index, function(){ alert( index ) });
the Click alerts the right value (3 or 4). All is fine.

But as soon as I put this inside a For-loop:
  1. for( var index = 3; index < 4; index++ ){
  2.       $(document).on("click", "#veld_" + index, function(){ alert( index ) });
  3. }
it works the same but alerts at each field the last value for index ( 5 in this example ). I also tried
  1. $("#veld_" + index).click(function(event){ alert( index ) });
With the same result.

Please help!!!