2

I have textboxes that when the user click on one of the textbox, all other textboxes will be disabled. It is working fine in firefox, what i can not understand is that, the enabling of the textbox doesn't work in IE10 (i cannot edit the value inside the textbox when enable(?). Below are my jquery codes, am i missing something for IE10? i have tried .prop('disable', false), .prop('readOnly', false) but nothing works in IE10 but in firefox i have no problem. please help.

Textbox onclick event:

function DisableTboxExceptActiveTxbox(txtbox) {
  $('input[id*="tbxQty"]').attr("disabled", true);
  $(txtbox).removeAttr("disabled");
}

Cancel Button onclick event:

function CancelUpdate(btn) {
  $('input[id*="tbxOrderQty_"]').removeAttr('disabled');
}

2 Answers 2

4

You should use .prop('disabled', true|false) when disabling or enabling the textboxes, not attr('disabled', true) and removeAttr('disabled'). So the proper code would be:

function DisableTboxExceptActiveTxbox(txtbox) {
  $('input[id*="tbxQty"]').prop("disabled", true);
  $(txtbox).prop("disabled", false);
}

UPDATE:

It appears that the first statement is causing IE 10 and 11 to make the current textbox disabled, and despite the second line removing the disabled property, IE re-adds it when you start interacting with the text box. You can see this when you look at the DOM Explorer while running the code.

Try this code instead:

function DisableTboxExceptActiveTxbox(txtbox) {
  $('input[id*="tbxQty"]').not(txtbox).prop("disabled", true);
}

See also this fiddle: http://jsfiddle.net/pX6Kv/2/

This selects all of the textboxes, then filters out the current textbox, then sets the remaining to disabled. Interesting bug. I'll file it with Microsoft, if it's not already.


You should consider adding a class to each of these textboxes rather than using [id*="tbxQty"], as it would be faster in most browsers.

Then, the CancelUpdate:

function CancelUpdate(btn) {
  $('input[id*="tbxOrderQty_"]').prop('disabled', false);
}

You may also want to be more consistent how you're going to abbreviate "textbox", as tbx, txtbox, Tbox or Txbox are all used. Just a suggestion though :)

8
  • i've already tried those but they wont work also in IE10. It does works in firefox but not in IE10.
    – sd4ksb
    Commented Jun 17, 2014 at 22:57
  • Here's a working version of this kind of thing: jsfiddle.net/pX6Kv can you confirm whether that works in IE10? If so, it may be a problem in how your handlers are bound to the text boxes themselves. Commented Jun 17, 2014 at 23:05
  • it is definitely the IE10. your jsfiddle doesnt work also there.
    – sd4ksb
    Commented Jun 17, 2014 at 23:09
  • What are you expecting it to do? When I run that jsfiddle in IE10, I get two text boxes and a button. When I click into one of the text boxes, the other is disabled. When I click the button, both become enabled. Commented Jun 17, 2014 at 23:12
  • you cannot key-in a value in the textbox. is the editing of value differs from the enabled attribute of the textbox?
    – sd4ksb
    Commented Jun 17, 2014 at 23:22
-1

Let me know if this changes anything:

function DisableTboxExceptActiveTxbox(txtbox) {    
  $("input[type=text]").click(function (e) {
    $("input[type=text]").attr("disabled", true);
    $(this).removeAttr("disabled");
  }
}
1
  • hmm, Could you paste the html code after you click? Just to see how the markup is... Commented Jun 17, 2014 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.