0

I am using this code for accessing the attribute of the button throught the id of one of the form fields.. but it isn't working..

$(document).ready(function() {

    if (document.getElementById("idadminusername").style.color == 'red') {    

        $("#btn").attr("disabled", "true");   
    }
}
rbento
  • 9,919
  • 3
  • 61
  • 61
Jay Jani
  • 1
  • 1
  • 1
    Possible duplicate of [jQuery disable/enable submit button](http://stackoverflow.com/questions/1594952/jquery-disable-enable-submit-button) – harogaston Jul 02 '16 at 18:06
  • Apart from the technical solution, disabling/enabling buttons depending on another element's css style is something a team mate might want to kill you for :) – Jan B. Jul 02 '16 at 18:10

2 Answers2

1
   $(document).ready(function() {
            if (document.getElementById("idadminusername").style.color == 'red') {

                $('#btn').prop('disabled', true);


            }
        }
SaiKiran
  • 6,244
  • 11
  • 43
  • 76
0

To disable a for field you need to do e.g. this:

html

<form>
  <input id="foo"/>
  <input id="bar"/>
</form>

js

$("#foo").prop('disabled', true);

https://jsfiddle.net/vdkm7phw/

rwx
  • 696
  • 8
  • 25