0

I've been battling with this issue all day. I am hoping someone has an answer for me. I did a bunch of searching and can't seem to find an answer.

I have a page that has 3 forms on it. I am working within the 2nd form. None of the forms are embedded within another form.

I have a hidden div that contains two form elements, a drop down list and a text box, and a submit button that I anticipated it posting to the form it is enclosed in. On another button within the form itself (not submit button), I have javascript that launches jquery.Dialog, that code looks like this:

function showReleaseDiv() {
    var div = $("#ReleaseHoldsDiv");
    var f = div.closest("form");
    div.dialog({ width: 270, height: 187, modal: true, title: 'Bulk Hold Resolution' });
    div.parent().appendTo(f);
}

This part does function correctly. I've overcome the typical jquery issue where it pulls the contents of the dialog out of the form, so I put it back in the form, but wonder if this is causing my real issues which are:

The drop down list and text box are both required before I post, so I default the submit button to disabled, then I have an onchange event on the drop downlist, and the onkeyup on the text box call the following javascript:

function enablePopupRelease() {
    var button = $("PopupReleaseButton");
    if (button && button != null) {
        button.attr("disabled", "disabled");
        if ($("#ResolutionTypeCode").val() != "" && $("#ResolutionComments").val() != "") {
            button.removeAttr("disabled");
        }
    }
    return true;
}

Both events fire correctly and I step through the code; all seems fine, but the button disable state does not change.

Please help.

6
  • 1
    Side note, the if(button && button != null) is unnecessary, if nothing matches button, it will just be an empty jquery object. But if you do want to test, you should use if(button.length) Commented Feb 21, 2012 at 22:31
  • Using any method you wish, can you check to see if the attribute is actually removed? Commented Feb 21, 2012 at 22:31
  • 1
    Is there a '#' missing in the var button = $("PopupReleaseButton"); line? Commented Feb 21, 2012 at 22:31
  • Yes, I just noticed that as well... Commented Feb 21, 2012 at 22:32
  • Holy #$@# !!!! I reviewed this code so many times - I even had a coworker look at it! Can you put bad words in here? Damn it! Good catch pluckerpluck! I'm officially demoting my ability to post on stackoverflow! Commented Feb 21, 2012 at 22:49

4 Answers 4

2

I believe you are missing a hash on this line:

Change:

var button = $("PopupReleaseButton");

to

var button = $("#PopupReleaseButton");
Sign up to request clarification or add additional context in comments.

Comments

0

firstly I would clean some code as follows:

function enablePopupRelease() {     var button = $("PopupReleaseButton");     if (button) {         button.attr("disabled", "disabled");         if ($("#ResolutionTypeCode").val() && $("#ResolutionComments").val()) {             button.removeAttr("disabled");         }     }     return true; } 

Let me know if makes any difference please?

if you break through the code ... does it stop at button.removeAttr("disabled"); please?

Comments

0

Are you using the jQuery UI button widget for the form's submit button? If so, you will need to call

$("#PopupReleaseButton").button({disabled: true});

to disable the button.

Comments

0

disabled isn't an attribute, it's a property -- try using button.prop('disabled',true) and button.prop('disabled',false) instead.

http://api.jquery.com/prop/

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.