2

I'm trying to make a button available only if the content of an input changed this way:

$(document).ready(function() {
    $('input[name="tesztinput1"]').keyup(function(){
          alert('Content has been changed');
          if ($(this).val())
          {
            $('input[name="tesztinput3"]').removeAttr('disabled');
          }
        })
});

And in the HTML:

<input name="tesztinput1" type="text"/>
<input name="tesztinput3" type="button" disabled="disabled" value="Click"/>

It properly works if the element which i want to remove disable attribute is a text input aswell but not working on buttons and submit elements. Any idea?

So this part of the code itself seems to be okay I tested every suggestion in the recent answer and no result. What else could block me from executing an action like this?

erik.c
  • 1,342
  • 2
  • 15
  • 27

3 Answers3

2

Use .prop(),

To disable

 $('input[name="tesztinput3"]').prop('disabled', true);

To enable

 $('input[name="tesztinput3"]').prop('disabled', false);

DEMO

Also read .prop() vs .attr()

Community
  • 1
  • 1
Satpal
  • 132,252
  • 13
  • 159
  • 168
0

Well, I didn't succeed in solving the problem but i found a workaround: I use readonly instead of disabled, because of something it works correctly.

erik.c
  • 1,342
  • 2
  • 15
  • 27
0

You can use a "Input" rather than "Button":

$('input[name="tesztinput3"]').prop('disabled', false); 

Just work in a "Input".

Kos
  • 4,890
  • 9
  • 38
  • 42