View difference between Paste ID: 0QTZzX6X and vmHhgkXQ
SHOW: | | - or go back to the newest paste.
1
function postForm(form) {
2
    var $this = $(form);
3
    var string = $this.serialize();
4
    $.ajax({
5
        type: "POST",
6
        url: "add_room.php",
7
        data: string,
8
        cache: false,
9
        success: function(data){
10-
            var saveIcon = $this.siblings('.saveIcon');
10+
            var saveIcon = $this.find('.saveIcon');
11-
            $this.siblings('[type=hidden]').val(data);
11+
            $this.find('[type=hidden]').val(data);
12
            saveIcon.fadeIn(750);
13
            saveIcon.delay(500).fadeOut(750);
14
            $('#message').text('The id of the inserted information is ' + data);
15
        }
16
    });
17
}
18
19
function autosave() {
20
    $('form').each(function() {
21
		postForm(this);
22
    });
23
}
24
setInterval(autosave, 10 * 1000);
25
$(document).ready(function() {
26
    $('body').on('click', '.save', function(e) {
27
        postForm($(this).closest('form').get(0));
28
    });
29
30
    $('#addForm').on('click', function(){
31
        $('<form method="post" action="add_room.php"><label for="itemName[]">Item</label><input type="text" name="itemName[]"><label for="itemPhoto[]">Photo</label><input type="text" name="itemPhoto[]"><input type="hidden" name="itemId[]" value=""><input type="hidden" name="itemParent[]" value="<?=$_GET["room"]?>"><div class="saveIcon" style="display: none; color: green;">SAVED!</div><div class="save">Save Item</div></form>').fadeIn(500).appendTo('.addItem');
32
    });
33
});