Noongar Posted March 15, 2012 Share Posted March 15, 2012 I have a problem where my function doesn't seem to be even parsing. <SCRIPT> function unknownName() { if (document.forms['form']['targetname'].disabled = false) { document.forms['form']['targetname'].disabled = true; } if (document.forms['form']['targetname'].disabled = true) { document.forms['form']['targetname'].disabled = false; } } </SCRIPT> <INPUT name="unknownname" onclick="return unknownName()" type="checkbox"> When I click it, the INPUT that its suppose to disable doesn't disable. I don't even get an error message in my error console which suggests that the function isn't even parsing. Does anyone know what the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/258961-function-doesnt-seem-to-parsing/ Share on other sites More sharing options...
nogray Posted March 15, 2012 Share Posted March 15, 2012 if (document.forms['form']['targetname'].disabled = false) needs == for comparson, same with the other if statment and your if statments will cancel each other if the field is disabled. Maybe you need to use else if. Quote Link to comment https://forums.phpfreaks.com/topic/258961-function-doesnt-seem-to-parsing/#findComment-1327527 Share on other sites More sharing options...
Noongar Posted March 15, 2012 Author Share Posted March 15, 2012 Your right about the equal signs man. How didn't I see this! Thanks! "your if statments will cancel each other if the field is disabled. Maybe you need to use else if." I don't understand what you mean. Could you give me an example? Now my error console reports "unknownName is not defined". How is that so?! Quote Link to comment https://forums.phpfreaks.com/topic/258961-function-doesnt-seem-to-parsing/#findComment-1327530 Share on other sites More sharing options...
nogray Posted March 15, 2012 Share Posted March 15, 2012 If the field was not disabled and you called the function, the first if statment will disable it and the second if statment will check if it's disabled (and it's because the first if statment) and enable it. instead you can if else statment instead of two if statments. Quote Link to comment https://forums.phpfreaks.com/topic/258961-function-doesnt-seem-to-parsing/#findComment-1327538 Share on other sites More sharing options...
Noongar Posted March 15, 2012 Author Share Posted March 15, 2012 Thanks mate. function unknownName() { if (document.forms["form"]["targetname"].disabled == false) { document.forms["form"]["targetname"].disabled = true; } else { document.forms["form"]["targetname"].disabled = false; } } Solved. Quote Link to comment https://forums.phpfreaks.com/topic/258961-function-doesnt-seem-to-parsing/#findComment-1327640 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.