Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Problem validation date jQuery?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #34961
    binboy
    Participant

    I want create a validation for date i don’t know why output function `valid_date()` in ` $(‘.submit’).submit(… alert(valid_date()); … ` after click on button is `undefined`, how can fix it?


    function valid_date() {
    $(document).delegate('input.date:text', 'keyup change', function () {
    var class_show = '.' + $(this).closest('div.auto_box2').find('div:last').attr('class');
    $val = $(this).val().replace(/[^d]+/g, "").match(/d{1,12}$/);
    var $this = $(this);
    val = $this.val();
    name = $this.closest('div.auto_box2').find('input').attr('name');
    url = $this.attr('class').split(" ")[0];
    filter = $this.attr('class').split(" ")[2];
    var class_age = '.' + $(this).closest('div.age').find('input[name="age"]').attr('class');
    if (filter == "limitdate") {
    dataObj = 'limit_date=' + val;
    } else {
    dataObj = 'date=' + val;
    }
    $(class_show).empty().attr('style', '');
    //alert(filter);
    if (val.match(/^dddd/dd/dd$/)) {
    var result = true;
    $.ajax({
    type: "POST",
    dataType: "JSON",
    url: url,
    data: dataObj,
    cache: false,
    success: function (data) {
    //alert(data);
    if (data == null) {
    $(class_show).attr('style', 'margin: 0 5px 0 0; color: #7E7E7E; background-color: #ffffec; height: 26px; padding: 2px 3px 0 3px; font-size: 13px;');
    $(class_show).show().html('Is wrong.');
    $(class_age).val('0');
    $('.' + filter).css("background", "#ffc4c4");
    result = false;
    } else {
    $(class_show).show().html('');
    $(class_show).attr('style', 'margin: 0 5px 0 0; color: #7E7E7E; background-color: #ffffec; height: 26px; padding: 2px 3px 0 3px;')
    $('
    ' + data.date + '').appendTo(class_show);
    $(class_age).val(data);
    $('.' + filter).css("background", "#FFFFEC");
    }
    },
    "error": function (x, y, z) {
    // callback to run if an error occurs
    alert("An error has occured:n" + x + "n" + y + "n" + z);
    }
    });
    } else {
    $('.' + filter).css("background", "#ffc4c4");
    result = false;
    }
    return result;
    });
    }
    //submit form ////////////////////////////////////////////////////////
    $('.submit').submit(function () {
    //ticket_check();
    var passed = true;
    alert(valid_date());
    passed = valid_date() && passed;
    //passed = autocomplet_valid() && passed;
    //passed = ticket_check() && passed;
    //passed = required_selectbox() && passed;
    //passed = required_valid() && passed;
    if (!passed) {
    $('#loadingDiv, #overlay').hide();
    return false;
    }
    });
Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.