Click here to Skip to main content
15,891,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear friends

I'm using a webgrid in MVC, I want to clear that field after the validation.
my code is



C#
//To validate the date
function FutureDateValidation(Indx) {

    var ExpDateTxt = '#txtExpDate' + Indx.toString();
    var mCurDt = $('#CurDate').val();
    var ExpDate = $(ExpDateTxt).val();

   
    if (CompareDates(mCurDt, ExpDate) == false) {

        PopupMessage("Required", " The Expiry date should be greater than current date", "alert");

        //        $('#' + ExpDateTxt).tex = "";

        $('#' + ExpDateTxt).focus();
        e.stopPropagation();
        return false;

    }
    else {
        e.stopPropagation();
        return true;
    }
}





After the message popup message, i want to clear or make null #txtExpDate this field.
Thanks for ur help.
Posted
Comments
Solai Raja 3-Mar-15 2:08am    
$('#' + ExpDateTxt).val("");

1 solution

I think the below will do...
JavaScript
$(ExpDateTxt).val('');

Refer - .val()[^]
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 3-Mar-15 2:09am    
+5Even .val(null) should work...
I should add also the link for .val() method: http://api.jquery.com/val
Thanks Kornfeld. :) Answer updated.
shahed.sohail 3-Mar-15 5:49am    
Thanks Tadit,
$(ExpDateTxt).val('');this works for me.

In my project, i have to fields same like the above
$(txtTotalPrice1).val('');
$(txtRecQty).val('');

txtTotalPrice1 is readonly but it is not clearing the value when i used this
$(txtTotalPrice1).val('');

thanks for ur help
shahed.sohail 3-Mar-15 5:50am    
txtTotalPrice1 field is readonly field but it is not clearing the value when i used this
$(txtTotalPrice1).val('');
any help
You cannot set value inside the readonly textbox. Instead try to do like below... First make readonly false, then set blank and make readonly again.

$(txtTotalPrice1).prop("readonly",false);
$(txtTotalPrice1).val('');
$(txtTotalPrice1).prop("readonly",true);

Let me know if it works or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900