Anon-e-mouse Posted February 25, 2012 Share Posted February 25, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257782-disabling-externally/ Share on other sites More sharing options...
kicken Posted February 26, 2012 Share Posted February 26, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/257782-disabling-externally/#findComment-1321287 Share on other sites More sharing options...
Anon-e-mouse Posted February 26, 2012 Author Share Posted February 26, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/257782-disabling-externally/#findComment-1321300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.