JQuery object never changes except the first

I have a problem with the object I'm trying to modify. An object has a certain number of keys in a format key_yyyy-mm-dd. When certain input fields lose focus, I run a function to change the object. This function is as follows:

function updateHotelBooking()
    {
        $(".no_hotel").each(function(i) {
            var day = $(this).attr('name').match(/\[(.*?)\]/)[1];
            hotelBooking["key_" + day] = parseInt($(this).val());
        }); 
    }

.no_hotel are text fields that trigger the function, and they also provide the value that I want to put in my object.

Now, let's say I put 3in my first text box, it console.logwill return the following object:

Object
key_2011-08-21: 3
key_2011-08-22: 0
key_2011-08-23: 0
key_2011-08-24: 0
key_2011-08-25: 0

, - ( , ), , . , , 5, 3.

, . , console.log day $(this).val() . , .

- ? !

EDIT:

hotelBooking $(document).ready():

var hotelBooking = {};

, updateHotelBooking, :

$(".roomrequest").blur(function()
{
    updateHotelBooking();
});

EDIT2: JSFiddle: http://jsfiddle.net/pBYeD/2/

+5
2

- , , , , :

    function updateHotelBooking()
    {
        $(".no_hotel").each(function(i) {
            var day = $(this).attr('name').match(/\[(.*?)\]/)[1];
            hotelBooking["key_" + day] = parseInt($(this).val());     
            **logObject(hotelBooking);**      
        });     
    }  


function logObject(hotelBooking){
        for(var i in hotelBooking){
            console.log(i+": "+hotelBooking[i]);
        }
        console.log("------");
    }
+1

, ?

chrome, , ( +3). , - console.log(hotelBooking["key_" + day]); , .

+1

All Articles