Jump to content

Disabling externally


Anon-e-mouse

Recommended Posts

Evening,

 

I currently have a php file whereby options are select from two drop down menus. This "onchange" calls the check function which sends the combination to another file finally finishing in the final function as seen below:

 

function updateFinal() {
     if (ajax.readyState == 4) {
     if (ajax.status == 200) {
        var AjResp = ajax.responseText;

            if(AjResp == 'YES'){

                document.getElementById("check").disabled = false;

            } else {

                document.getElementById("check").disabled = true;
                
            }
            
        }
        
    }
    
}

 

The file is included in the header but when I try it and get a YES response from the middle file the button isn't actually disabled? Is that because the function is attempting to disable an element in the function file itself?

 

If not, I'm lost.

 

 

Link to comment
Share on other sites

Whether the file is included in the head/body or externally/internally doesn't matter, it all runs in the same context.  If your button is not disabling then my first guess would be that your script can't find it and the getElementById call is failing.  You should get an error message if this is the case (unless it's being caught somewhere which some frameworks do if your using one).

 

We'll need to see more code to help much further.  The HTML code at least, maybe more of the JS.

 

Try splitting your lines and logging the variable between steps to see what is going on.

 

var check = document.getElementById("check");
console.log(check);
if(AjResp == 'YES'){
    console.log('disable=false');
    check.disabled=false;
}
else {
   console.log('disable=true');
   check.disabled=true;
}

 

Link to comment
Share on other sites

Hi kicken,

 

Thanks for your reply! I looked at the code just as your post notification came through and realised I had made a ridiculously stupid mistake and hadn't assigned the button its id as being "Check", which when I ammended it worked as I expected.

 

Shows how much I was paying attention, although your logging method is certainly something I will be using in future.

 

Thanks,

Anon!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.