TAGS :Viewed: 1 - Published at: a few seconds ago

[ Clear Enabled textboxes in form using jquery ]

I need to clear/reset the textbox value when it is set to read only = true or Enabled = false . I used reset function in my code but this doesnt work . My code as

function resetForm($form) {
    $form.find('input:text, input:password, input:file, select').val('');   
    $("input[type='hidden']", this).each(function () {
        this.value = '';
    });    
    $form.find('input:checkbox')
         .removeAttr('checked').removeAttr('selected');

}

 <asp:TextBox ID="txteventid" runat="server" ReadOnly="true"/>

Any suggestions ..

Answer 1


I am not sure what your reset function is doing because I cannot see the if condition for the read only check, but you could try this: < given from your code: > :)

i.e. use API ; .prop http://api.jquery.com/prop/ and check what is the state of the property or attribute:

rest hope this help for your purpose :)

if you keen: .prop() vs .attr()

and this might come handy: Check existence of an attribute with JQuery

  function resetForm($form) {
    $form.find('input:text, input:password, input:file, select').val('');   
    $("input[type='hidden']", this).each(function () {
        if($(this).prop('readonly')){ // you could check with string i.e. $(this).prop('readonly') === "true"
         this.value = '';
        }
    });    
    $form.find('input:checkbox')
         .removeAttr('checked').removeAttr('selected');

}

 <asp:TextBox ID="txteventid" runat="server" ReadOnly="true"/>