views:

15

answers:

1

i'm using jquery in report section in my asp.net mvc project.But i had problem with jquery validation.Here code don't work and doesn't show any message when the date input text field is left blank.

$(document).ready(function() {
        $("#FromDate").datepicker({ showOn: 'both', buttonText: "select Date", dateFormat: 'M d, yy' });
        $("#ToDate").datepicker({ showOn: 'both', buttonText: "select Date", dateFormat: 'M d, yy' });
        $("#ParticularDate").datepicker({ showOn: 'both', buttonText: "select Date", dateFormat: 'M d, yy' });

        $("#ddlRepoOpt").change(function() {
            var self = $(this);
            $("#repoopt").show();
            if (self.val() == "") {
                $("#reop2").hide();
                $("#reop1").hide();
                $("#reop3").hide();
                $("#optionUttOperators").hide();
                $("#optionUttTravelAgents").hide();
            }
            else if (self.val() == 1) {
                $("#reop2").show();
                $("#reop1").hide();
                $("#reop3").hide();
                $("#optionUttOperators").show();
                $("#optionUttTravelAgents").show();
            }
            else if (self.val() == 2) {
                $("#reop1").show();
                $("#reop2").hide();
                $("#reop3").hide();
                $("#optionUttOperators").show();
                $("#optionUttTravelAgents").show();
            }
            else {
                $("#reop1").hide();
                $("#reop2").hide();
                $("#reop3").show();
                $("#optionUttOperators").show();
                $("#optionUttTravelAgents").show();

            }
            $("#generateReport").show();
        });

        **$("#generateReport").live("click", function(e) {
                var sd = $("#FromDate").val();
                var ed = $("#ToDate").val();
                var pd = $("ParticularDate").val();
            if (sd == "" && ed == "" && pd=="") {
                alert("Please select the dates");
                e.preventDefault();
                return false;
            }
        });

    });

i had problem with following part.here no alert message is dispaly when textbox field is left empty.

   $("#generateReport").live("click", function(e) {

                var sd = $("#FromDate").val();
                var ed = $("#ToDate").val();
                var pd = $("ParticularDate").val();
            if (sd == "" && ed == "" && pd=="") {
                alert("Please select the dates");
                e.preventDefault();
                return false;
            }
        });
A: 

Try this instead:

   $("#generateReport").live("click", function(e) {
        var sd = $("#FromDate").val();
        var ed = $("#ToDate").val();
        var pd = $("#ParticularDate").val();
        if ((sd == null || sd.length < 1) && (ed == null || ed.length < 1) && (pd == null || pd.length < 1)) {
            alert("Please select the dates");
            e.preventDefault();
            return false;
        }
    });
Garis Suero
thanks...it work well....
Mik-Mark
Good, this is why stackoverflow is here...
Garis Suero