Hi,

I wrote a small piece of javascript a while ago to add some text to a text box and mark it as read only if a check box was checked. If the checkbox was unchecked, the text would be removed and the field writable.

It was working great until I accadently deleted the file and had to start over from an old backup that didn't have the new functionality.. Now I have it so if you check the box, it puts the correct text, and marks the field read only, hoverer now I can't uncheck the checkbox.

Here is what I have this far:

javascript

<script type="text/javascript">
	function disabler()
	{
		if (document.forms[0].micro.checked = true){
			document.forms[0].status.value='...some text...';
			document.forms[0].status.readOnly = true;
		} else if (document.forms[0].micro.checked = false){
			document.forms[0].status.value='';
			document.forms[0].status.readOnly = false;
		}
	}
</script>

HTML

shipping/tracking number:<input type='text' name='status' id='status'> (<input type='checkbox' name='micro' id='micro' onchange='disabler()'> : Micro Note)

thanks for any help!

Recommended Answers

All 2 Replies

1. It probably isn't a good idea to use the word 'status' as a field name. It is a reserved word
2. your comparison needs to have a double equal rather than a single - if(foo==bar)
3. you don't need an else if, you just need else

HTML

<input type=text name="microstatus" id="microstatus" value="...bla..."><input type=checkbox name=micro id=micro value=1 onclick="disabler(this);">

JAVASCRIPT

function disabler(obj){
  if(obj.checked==true){document.forms[0].microstatus.readonly=true;document.forms[0].microstatus.value="..bla...";}else{document.forms.microstatus.readonly=false;document.forms[0].microstatus.value=""}
}

That did it!

Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.