1

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 ..

kk1076
  • 1,740
  • 13
  • 45
  • 76

1 Answers1

2

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: Select elements by attribute

  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"/>
Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • no, its not working, can you tell this.prop('readonly') specifies the textbox ?? – kk1076 Jul 12 '12 at 10:50
  • hey @kk1076 can you flick a demo; finding bit hard as to what is not working, `:)` **or** put an alert for this `alert($('#txteventid').prop('ReadOnly'));` lemme know what do you get in return, we will sort it out not to worry – Tats_innit Jul 12 '12 at 10:53
  • fine. As you mentioned above, the alert appears as undefined. i tried as dis if $('MainContent_uscEventParameters_txteventid').prop('ReadOnly')) { document.getElementById("'MainContent_uscEventParameters_txtevent").value = ""; } but its not clearing the value. – kk1076 Jul 12 '12 at 11:16
  • @kk1076 cool so it do not register your element whic you mentioned above, can you please make a demo / jsfiddle I can help you out better if you can replicate it in demo, cheers `:)` – Tats_innit Jul 12 '12 at 11:24