Set ReadOnly Property With CheckBox Value

Discussion in 'Javascript' started by crjunk, Jul 21, 2005.

  1. crjunk

    crjunk Guest

    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
    crjunk, Jul 21, 2005
    #1
    1. Advertising

  2. crjunk

    crjunk Guest

    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
    crjunk, Jul 21, 2005
    #2
    1. Advertising

  3. crjunk

    ASM Guest

    crjunk wrote:
    > 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)" />


    --
    Stephane Moriaux et son [moins] vieux Mac
    ASM, Jul 21, 2005
    #3
  4. crjunk

    crjunk Guest

    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
    crjunk, Jul 22, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    5
    Views:
    7,016
    Bob Barrows [MVP]
    Jun 6, 2006
  2. Replies:
    0
    Views:
    402
  3. Doogie
    Replies:
    5
    Views:
    1,853
    E-ric
    Oct 10, 2012
  4. Patrik

    Set readonly property on cell level in a datagridview

    Patrik, Feb 15, 2007, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    507
    Steven Cheng[MSFT]
    Feb 16, 2007
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    1,869
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page