leefpatroon_submit.js 1.83 KB
Newer Older
1 2 3 4 5
/* leefpatroon_submit.js wordt aangeroepen in leefpatroon.php
 * deze bestand zorgt voor het doorsturen van de data uit het leefpatroon_base.php
 * formulier naar check_input.php en ook dus om meldingen te weergeven 
 * zonder de pagina te herladen
 */
6 7 8 9 10 11 12
var count = 0;

$('form.ajax').on('submit', function () {
    var that = $(this),
            url = that.attr('action'),
            type = that.attr('method'),
            data = {};
KYC's avatar
KYC committed
13

14 15 16 17 18 19 20 21 22
    // find all attributes with name
    that.find('[name]').each(function (index, value) {
        var that = $(this),
                name = that.attr('name'),
                value = that.val();
        data[name] = value;
    });

    // find the value of radio 
23 24 25 26 27 28 29 30 31
    var radiobtnName = $('input:radio:checked').attr('name');
    var radiobtn = $('input:radio:checked').val();
    data[radiobtnName] = radiobtn;
    
    // find the value of the hidden field
    var activityName = $('#getActivityID').attr('name');
    var activityid = $('#getActivityID').val();
    data[activityName] = activityid;
    
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    $.ajax({
        url: url,
        type: type,
        data: data,
        success: function (data) {
            // counts submit clicks
            count++;

            // checks if submits is greater than 1, then show without animation
            if (count > 1) {
                $('#melding').show();
            }

            // if the div alert is hidden(standard), show it after submitting
            if (!$('#melding').is(":visible")) {
                $('#melding').delay(250).fadeIn(700);
            }
49 50
            // Opslaan button tekst & effect
            $('#opslaan').hide().html("Opslaan").fadeIn(900);
51 52 53 54

            // insert data to the specific id
            $('#melding_msg').html(data);
        }
KYC's avatar
KYC committed
55
    });
56 57 58 59 60
    return false;
});

$('form.ajax').on('reset', function () {
    location.reload();
61
});