Hard Checkboxes Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • listsubscriber@hotmail.com

    #1

    Hard Checkboxes Question

    I am pretty new to using JavaScript for web applications. I need to
    get some code that disables the input text box until the checkbox
    beside is checked. Any examples of accomplishing this task?

    Thanks.

  • McKirahan

    #2
    Re: Hard Checkboxes Question

    <listsubscriber @hotmail.com> wrote in message
    news:1106536943 .792408.41540@c 13g2000cwb.goog legroups.com...[color=blue]
    > I am pretty new to using JavaScript for web applications. I need to
    > get some code that disables the input text box until the checkbox
    > beside is checked. Any examples of accomplishing this task?
    >
    > Thanks.[/color]


    Will this help? Watch for word-wrap.

    <html>
    <head>
    <title>boxtext1 .htm</title>
    </head>
    <body>
    <form action="" method="post" name="form1">
    <input type="checkbox" onclick="docume nt.form1.data.d isabled=false">
    <input type="text" name="data" disabled></p>
    </form>
    </body>
    </html>

    Or this:

    <html>
    <head>
    <title>boxtext2 .htm</title>
    <script type="text/javascript">
    function enable() {
    var form = document.form1;
    form.data.disab led = false;
    form.data.style .backgroundColo r = "#FFFFFF";
    form.data.focus ();
    }
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="">
    <input type="checkbox" onclick="enable ()">
    <input type="text" name="data" disabled
    style="backgrou nd-color:#EEEEEE"> </p>
    </form>
    </body>
    </html>


    Comment

    • McKirahan

      #3
      Re: Hard Checkboxes Question

      "McKirahan" <News@McKirahan .com> wrote in message
      news:Vo2dnbxCHa r452ncRVn-1g@comcast.com. ..

      [snip]

      Please ignore "</p>" in my prevous post.



      Comment

      • Michael Winter

        #4
        Re: Hard Checkboxes Question

        On Sun, 23 Jan 2005 22:34:09 -0600, McKirahan <News@McKirahan .com> wrote:

        [snip]
        [color=blue]
        > <input type="text" name="data" disabled>[/color]

        Disabling a form control in HTML will render it useless to anyone without
        Javascript. The better approach is to disable the control with Javascript
        - then you know the control can be enabled later.

        [snip]

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • listsubscriber@hotmail.com

          #5
          Re: Hard Checkboxes Question

          Thanks for the replies. I think I am going to go with the 'or this:'
          solution provided above. It seems to work with only minor tweaking to
          handle the user checking and unchecking the box.
          Thanks again. U guys are tooooo smart!

          Comment

          • RobB

            #6
            Re: Hard Checkboxes Question

            listsubscriber@ hotmail.com wrote:[color=blue]
            > Thanks for the replies. I think I am going to go with the 'or this:'
            > solution provided above. It seems to work with only minor tweaking[/color]
            to[color=blue]
            > handle the user checking and unchecking the box.
            > Thanks again. U guys are tooooo smart![/color]

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">

            <html>
            <head>
            <title>untitled </title>

            <script type="text/javascript">

            function initEnable()
            {
            function set_enable()
            {
            this.tbox.disab led = !this.checked;
            this.tbox.selec t();
            if (!this.checked)
            this.tbox.value = this.tbox.defau ltValue;
            }

            var f = document.forms, flen = f.length, el, els, j;
            for (var i = 0; i < flen; ++i)
            {
            els = document.forms[i].elements;
            j = 0;
            for (; j < els.length; ++j)
            {
            el = els[j];
            if (/\benable\b/.test(el.classN ame))
            {
            el.tbox = els[++j];
            el.onclick = set_enable;
            el.onclick();
            }
            }
            }
            }

            window.onload = initEnable;

            </script>
            </head>
            <body>
            <form style="width:18 0px;">
            <input class="enable" type="checkbox" />:::<input type="text" name="t1"
            value=" enter name" />
            <input class="enable" type="checkbox" />:::<input type="text" name="t2"
            value=" enter address" />
            <input class="enable" type="checkbox" />:::<input type="text" name="t3"
            value=" enter phone" />
            <input class="enable" type="checkbox" />:::<input type="text" name="t4"
            value=" enter email" />
            <br />
            <input type="checkbox" /><input type="text" name="t5" value="test" />
            </form>
            </body>
            </html>

            Comment

            Working...