Set ReadOnly Property With CheckBox Value

C

crjunk

I want to set a textbox's ReadOnly value to the OPPOSITE value that the
CheckBox has. For example: If the user checks the CheckBox then the
ReadOnly property for the TextBox is set to False. The default value of
the TextBox is set to false. Am I on the right path or am I totally
off in left field?


<input type="checkbox" name="chkCode1" value="ON"
onclick="document.DisplayCodes.txtGrossPayroll1.readOnly !=
document.DisplayCodes.chkCode1">
<br>
<input type="text" style="text-align: right;" size="10" tabindex='1'
readonly="true" name="txtGrossPayroll1" value="0" width="10"
onkeyup="ComputePremium(1)" onkeypress="return blockNumbers(event)"/>


Thanks,
CR Junk
 
C

crjunk

I've gotten a little closer, but no completely. Instead of using the
ReadOnly property I tried the Disabled property. When I put a check in
the checkbox, the disabled property is set to false, but if I uncheck
the checkbox, the textbox is not disabled. Can someone tell me what
I'm missing?

<input type="checkbox" name="chkCode1" value="ON"
onclick="document.DisplayCodes.txtGrossPayroll1.disabled=
!document.DisplayCodes.chkCode1" />
<br>
<input type='text' style='text-align: right;' size='10' tabindex='1'
disabled='true' name='txtGrossPayroll1' value='0' width='10'
onkeyup='ComputePremium(1)' onkeypress='return blockNumbers(event)'/>

Thanks,
CR Junk
 
A

ASM

crjunk said:
I want to set a textbox's ReadOnly value to the OPPOSITE value that the
CheckBox has. For example: If the user checks the CheckBox then the
ReadOnly property for the TextBox is set to False. The default value of
the TextBox is set to false. Am I on the right path or am I totally
off in left field?

<input type="checkbox" name="chkCode1" value="ON"
onclick="txtGrossPayroll1.disabled = (this.checked);">
<br>
<input type="text" style="text-align: right;" size="10" tabindex='1'
readonly="true" name="txtGrossPayroll1" value="0" width="10"
onkeyup="ComputePremium(1)" onkeypress="return blockNumbers(event)" />
 
C

crjunk

Thanks for everyone's help. I was able to get it to work correctly by
referring ot ASM's example.

I came up with:
onclick="document.DisplayCodes.txtGrossPayroll1.disabled =
!(this.checked);"

Thanks again!

CR Junk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top