0

I have a function that works perfectly if you want to expand an input type=text with more than 20 characters. My problem is, how to apply this function for disabled inputs? To better understand the behavior of my function check my example on fiddle: http://jsfiddle.net/DCjYA/168/

$('input[type!="submit"]').focus(function(){
    if ($(this).val().length > 20) {
        $(this).attr('data-default', $(this).width());
        $(this).animate({width: 300}, 'slow');
        $(this).parent().addClass('cooling');
    }
}).blur(function(){ 
    var w = $(this).attr('data-default');
    $(this).animate({
        width: w
    }, 'slow');
    $(this).parent().removeClass('cooling');
});

Thank you.

Costique
  • 23,712
  • 4
  • 76
  • 79
mcmwhfy
  • 1,654
  • 5
  • 36
  • 58

2 Answers2

0

Since you can't get to focus an disabled element you should build a workaround for this. Or use another function for this?

EDIT: Probably this could be helpful for you: Event on a disabled input

Community
  • 1
  • 1
Daniel
  • 157
  • 2
  • 12
0

As Daniel said the focus and blur event will not work with the disabled input. Then for this purpose, hover, mouseenter or mouseover, mouseleave or mouseout are the events can be used but i could not find it working but i do found mousemove for expanding it. you can use it it it solve your problem.

$('input:disabled').mousemove(function(){
      if ($(this).val().length > 20) {
       $(this).attr('data-default', $(this).width());
       $(this).animate({width: 300}, 'slow');
       $(this).parent().addClass('cooling');
      }
});

fiddle : http://jsfiddle.net/raj_er04/DCjYA/174/

dku.rajkumar
  • 18,414
  • 7
  • 41
  • 58