Jump to content

Function doesn't seem to parsing


Noongar

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.