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");   
    }
}
2
  • 1
    Possible duplicate of jQuery disable/enable submit button Commented Jul 2, 2016 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 :) Commented Jul 2, 2016 at 18:10

2 Answers 2

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

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


            }
        }
Sign up to request clarification or add additional context in comments.

2 Comments

it's also possible that his if statement is false, if for example the button is set to red via CSS and not directly via the style attribute.
@Paul more explaination of question needed
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/

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.