PDA

View Full Version : Disabling/Enabling Text Boxes


Goldilocks
02-25-2004, 08:46 AM
What am I doing wrong here? The following code is meant to disable the textbox called txtNewIssue if the user selects a certain option from a dropdown box called DocStatusID. If they select any other option from the dropdown then the textbox should be enabled again.

The code I have so far seems to disable the box no matter what option I choose and then won't enable it again. I have checked the value that is being passed from the dropdown and it is correct. It is going to the correct part of the function depending on this, yet it still disables the textbox anyway. I am using IE6 if that helps.


<script language="javascript">
function ROstatus() {
alert(document.form1.DocStatusID.value);
//Document is rejected
if (document.form1.DocStatusID.value==2) {
alert("rejected")
document.form1.txtNewIssue.disabled='true';
return true;
}
//Document id Approved
else
{
alert("approved");
document.form1.txtNewIssue.disabled='false';
return true;
}
}
</script>

Topher
02-25-2004, 08:56 AM
In the following lines true and false shouldn't be in quotes for a start.
document.form1.txtNewIssue.disabled='true';
document.form1.txtNewIssue.disabled='false';
I would do it with the following:

<script language='javascript'>
<!--

function disable_text_box(select_value) {

if (select_value == 'value1') {
document.form1.txtNewIssue.diabled = true;
} else {
document.form1.txtNewIssue.diabled = false;
}

} // End of function

-->
</script>


Then in the body:

<select name='select1' onChange='disable_text_box(this.value)'>
<option value='value1'>Value 1</option>
<option value='value2'>Value 2</option>
<option value='value3'>Value 3</option>
</select>
Hope that helps.

Goldilocks
02-25-2004, 09:03 AM
Thanks for the help Topher, it worked. ;)