You must Sign In to post a response.
  • Category: JQuery

    How to Check null value in jquery


    Are you looking for a way to Check null value in jquery then read this thread to know how to check it

    Hi, i want to check any null value in textbox using jquery.

    in my application, want to check nearly 20 text boxes.

    this is my code. a function for checking null value

    function checking() {
    var empty = 0;
    $('input[type=text]').each(function () {
    if (this.value == "") {
    empty++;

    return false;
    }
    })

    }

    following is code for inserting

    $('#ainsert').click(function (e) {//a1insert
    e.preventDefault();
    );

    var vtype = $('#txtvtype').val();
    var vloc = $('#txtlocation').val();
    var vchrid = $('#txtvoucherid').val();
    var vdate = $('#txtvoucherdate').val();
    var vamt = $('#txtcash').val();

    $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "CashPaymentVoucher2.aspx/InsertVoucher",

    data: "{Vtype:'" + vtype + "',Vloc:'" + vloc + "',Vdate:'" + vdate + "',Vaccount:'" + vamt + "'}",
    dataType: "json",
    success: function (data) {
    alert(data.d);
    },
    error: function (xhr) {
    alert(xhr.responseText);
    }
    });

    });

    My requirement is if any textbox is null .insert button should'nt fired and empty text box's background clor should be red.

    How it is possible.

    Regards

    Baiju
  • #763457
    There may be a 'null' or 'unidentified' variable or control error exist in JQuery, to avoid it you can write a separate function to check if control/variable is 'null' or 'undefined'
    see below snippet

    function isNullAndUndef(variable)
    {
    return (variable !== null && variable !== undefined);
    }
    OR
    if(typeof variable_here === 'undefined'){
    // your code here.
    };

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments