#1
  1. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0

    Activate 2 text fields if checkbox is checked!


    Hi all


    I have been trying to find some examples with activate and deactivate from elements (text type inputs) when a checkbox is checked! So what I am looking for is activate 2 text inputs when the checkbox is checked and then deactivate the text inputs when the checkbox is unchecked. If anyone has any links where I can read up on this sort of thing I would be so happy, because everything I have tried does not work!

    ::EDIT::

    This is what I have, and it works, but how can I make it dynamic, so it can be used for more then 1 set of text boxes and 1 checkbox per set!

    CODE]
    <html>
    <head>
    <script>

    function Abox(z) {
    // how to make this if(dynamic)
    if (!document.form.name.checked) {
    z.blur();
    }
    }





    function Checkthis(x)
    {
    if (!x.checked) {
    // how to make these dynamic
    document.form.one.value = '';
    document.form.two.value = '';
    document.form.two.blur();
    document.form.one.blur();
    }

    }
    </script>
    </head>
    <body>
    <form name=form>
    <input type=checkbox name=name onclick="Checkthis(this);">
    <br>
    <input type=text name=one value='' onFocus="Abox(this);">
    <br>
    <input type=text name=two value='' onFocus="Abox(this);">
    </form>
    </body>
    </html>
    [/CODE]


    Thanks so much


    Sonia
    Last edited by Fataqui; November 1st, 2003 at 07:51 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    20
    Try this. It assumes your text inputs have id's 'input1' and 'input2'.
    Code:
    <script type="text/javascript">
    function toggleInputs(daCheckbox) {
    	// if .checked is true, disabled property of the inputs should be false
    	var disabled = ! daCheckbox.checked
    	document.getElementById("input1").disabled = disabled
    	document.getElementById("input2").disabled = disabled
    }
    </script>
    </head>
    <body>
    <form name="myform" action="">
    check: <input type="checkbox" onclick="toggleInputs(this)">
    <input type="text" id="input1" disabled="disabled">
    <input type="text" id="input2" disabled="disabled">
    </form>
    Hope this helps,
    Jeroen
  4. #3
  5. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi jerom



    Your way is so much better than mine, thanks!





    F!

IMN logo majestic logo threadwatch logo seochat tools logo