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
https://forums.phpfreaks.com/topic/257782-disabling-externally/
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;
}

 

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.