0

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!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by lobstar
0

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=""}
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.