enabling form elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stijn Goris

    #1

    enabling form elements

    hi all,

    I try to enable some form elements (positie and fotoToevoegen) when a user
    clicks a checkbox. Sadly enough it doesn't work I use the
    'onSelect="Enab leInput();'. The function is defined inside the form. Maybee
    someone knows the problem?

    kind regards
    Stijn

    <form name="nieuws" method="post"
    action="nieuwsV oegToe.php?acti e=nieuw&IDN=">
    Titel <input class="grijs" name="titel" type="text" size="40">
    <select class="grijs" name="type" >
    </select>
    <textarea class="grijs1" name="inhoud" cols="80"
    rows="8"></textarea><br><b r>

    <script LANGUAGE="JavaS cript">
    function EnableInput()
    {
    document.nieuws .positie.Disabl ed = "False";
    document.nieuws .fotoToevoegen. Disabled = "False";
    }
    </script>

    foto toevoegen? <input name="fotoToevo egen" type="checkbox" value="1"
    onSelect="Enabl eInput();"><br>
    <table class="grijs" bgcolor="#EEEEE E" >
    <tr><td>
    selecteer je foto:
    <input type="hidden" name="MAX_FILE_ SIZE" value="20000">
    <input type="file" name="foto">
    </td></tr>
    <tr>
    <td>
    <table>
    <tr>
    <td><img src="images/imageBoven.jpg" ></td>
    <td><img src="images/imageRechts.jpg "></td>
    <td><img src="images/imageOnder.jpg" ></td>
    <td><img src="images/imageLinks.jpg" ></td>
    </tr>
    <tr align="center">
    <td><input type="radio" name="positie" value="boven"></td>
    <td><input type="radio" name="positie" value="rechts"> </td>
    <td><input type="radio" name="positie" value="onder"></td>
    <td><input type="radio" name="positie" value="links"></td>
    </tr>
    </table>
    </td>
    </tr>
    </table><br>
    <input class="grijs" type="submit" value="nieuws toevoegen >>">
    </form>


  • Martin Honnen

    #2
    Re: enabling form elements



    Stijn Goris wrote:

    [color=blue]
    > document.nieuws .positie.Disabl ed = "False";[/color]

    The property is named disabled and the boolean value is false and not
    "False" so you need
    document.nieuws .positie.disabl ed = false;

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Grant Wagner

      #3
      Re: enabling form elements

      Stijn Goris wrote:
      [color=blue]
      > <script LANGUAGE="JavaS cript">[/color]

      <script type="text/javascript">

      The language attribute is deprecated.
      [color=blue]
      > function EnableInput()[/color]

      function EnableInput(the Form)

      Note the form reference now being passed to the function. This is to prevent
      needing to hard-code "document.nieuw s" later.

      I like to use Java syntax conventions in JavaScript, and I tend to use the
      shortest variable that will give me some indication of what the paramter is,
      which would make it "function enableInput(f)" , but use whatever you're
      comfortable with.
      [color=blue]
      > {
      > document.nieuws .positie.Disabl ed = "False";
      > document.nieuws .fotoToevoegen. Disabled = "False";[/color]

      theForm.positie .disabled = false;
      theForm.fotoToe voegen.disabled = false;

      false is a boolean, not a String, by setting the property to the String
      "false", you are in fact making it true (because a non-empty string evaluates
      to true). Also, JavaScript is case-sensitive, so the property "disabled" must
      be lowercase.
      [color=blue]
      > }
      > </script>
      >
      > foto toevoegen? <input name="fotoToevo egen" type="checkbox" value="1"
      > onSelect="Enabl eInput();"><br>[/color]

      onselect="Enabl eInput(this.for m);"

      Pass a reference to the form to the function. This gets picked up as "theForm"
      in the function and removes the need to hard-code the name of the form in the
      function (which means it doesn't break if you decide to rename the form).

      I like to make my attributes all lowercase in HTML, including JavaScript
      events. Since the attribute is part of the HTML markup and not JavaScript, it
      isn't case-sensitive.

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      • Stijn Goris

        #4
        Re: enabling form elements


        "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
        news:41068FB8.2 144D17E@agricor eunited.com...[color=blue]
        > Stijn Goris wrote:
        >[color=green]
        > > <script LANGUAGE="JavaS cript">[/color]
        >
        > <script type="text/javascript">
        >
        > The language attribute is deprecated.
        >[color=green]
        > > function EnableInput()[/color]
        >
        > function EnableInput(the Form)
        >
        > Note the form reference now being passed to the function. This is to[/color]
        prevent[color=blue]
        > needing to hard-code "document.nieuw s" later.
        >
        > I like to use Java syntax conventions in JavaScript, and I tend to use the
        > shortest variable that will give me some indication of what the paramter[/color]
        is,[color=blue]
        > which would make it "function enableInput(f)" , but use whatever you're
        > comfortable with.
        >[color=green]
        > > {
        > > document.nieuws .positie.Disabl ed = "False";
        > > document.nieuws .fotoToevoegen. Disabled = "False";[/color]
        >
        > theForm.positie .disabled = false;
        > theForm.fotoToe voegen.disabled = false;
        >
        > false is a boolean, not a String, by setting the property to the String
        > "false", you are in fact making it true (because a non-empty string[/color]
        evaluates[color=blue]
        > to true). Also, JavaScript is case-sensitive, so the property "disabled"[/color]
        must[color=blue]
        > be lowercase.
        >[color=green]
        > > }
        > > </script>
        > >
        > > foto toevoegen? <input name="fotoToevo egen" type="checkbox" value="1"
        > > onSelect="Enabl eInput();"><br>[/color]
        >
        > onselect="Enabl eInput(this.for m);"
        >
        > Pass a reference to the form to the function. This gets picked up as[/color]
        "theForm"[color=blue]
        > in the function and removes the need to hard-code the name of the form in[/color]
        the[color=blue]
        > function (which means it doesn't break if you decide to rename the form).
        >
        > I like to make my attributes all lowercase in HTML, including JavaScript
        > events. Since the attribute is part of the HTML markup and not JavaScript,[/color]
        it[color=blue]
        > isn't case-sensitive.
        >
        > --
        > Grant Wagner <gwagner@agrico reunited.com>
        > comp.lang.javas cript FAQ - http://jibbering.com/faq
        >[/color]

        thanks for the nice reply but I still have trouble making it work.

        I have the javascript function on top of the file

        <script type="text/javascript">
        function EnableInput(the Form)
        {
        theForm.positie .disabled = false;
        theForm.foto.di sabled = false;
        }
        </script>

        then the form
        <form name="nieuws" enctype="multip art/form-data" method="post"
        action="nieuwsV oegToe.php?acti e=nieuw&IDN=">
        Titel <input class="grijs" name="titel" type="text" size="40">
        <select class="grijs" name="type" >test</select>
        <textarea class="grijs1" name="inhoud" cols="80"
        rows="8"></textarea><br><b r>
        foto toevoegen? <input name="fotoToevo egen" type="checkbox" value="1"
        ondelect="Enabl eInput(this.for m);"><br>
        <table class="grijs" bgcolor="#EFEFE F" >
        <tr><td>
        selecteer je foto:
        <input type="hidden" name="MAX_FILE_ SIZE" value="20000">
        <input disabled type="file" name="foto">
        </td></tr>
        <tr>
        <td>
        <table>
        <tr>
        <td><img src="images/imageBoven.jpg" ></td>
        <td><img src="images/imageRechts.jpg "></td>
        <td><img src="images/imageOnder.jpg" ></td>
        <td><img src="images/imageLinks.jpg" ></td>
        </tr>
        <tr align="center">
        <td><input disabled type="radio" name="positie" value="boven"></td>
        <td><input disabled type="radio" name="positie" value="rechts"> </td>
        <td><input disabled type="radio" name="positie" value="onder"></td>
        <td><input disabled type="radio" name="positie" value="links"></td>
        </tr>
        </table>
        </td>
        </tr>
        </table><br>
        <input class="grijs" type="submit" value="nieuws toevoegen >>">
        </form>

        Thank in advance
        Stijn


        Comment

        • Harag

          #5
          Re: enabling form elements

          On Tue, 27 Jul 2004 17:23:34 GMT, Grant Wagner
          <gwagner@agrico reunited.com> wrote:


          [snipped]
          [color=blue]
          >I like to make my attributes all lowercase in HTML, including JavaScript
          >events. Since the attribute is part of the HTML markup and not JavaScript, it
          >isn't case-sensitive.[/color]

          Hi,

          I'm currently reading Javascript: the Definitive Guide, (Excellent
          book BTW) and find it very usefull.... That is also pointing out to
          use all the attributes in lowercase as its HTML. eg

          onclick, onmouseover, onmouseout

          But I'm having a problem with doing it this way.... it works fine in
          IE 6 But I also test my pages in NS 7.1 and that doesn't work when I
          put them in lowercase, it just seems to ignore the attibutes. I seem
          to have to put them as javascript:

          onClick, onMouseOver, onMouseOut.

          is it me or does everyone else get this problem ? is it a setting in
          NS ?

          Thanks

          Al.

          Comment

          • Grant Wagner

            #6
            Re: enabling form elements

            Stijn Goris wrote:
            [color=blue]
            > foto toevoegen? <input name="fotoToevo egen" type="checkbox" value="1"
            > ondelect="Enabl eInput(this.for m);"><br>[/color]

            checkbox inputs don't have an ondelect event, nor do they have an onselect event
            (well, they might, but it's not appropriate for this purpose). What you want is:

            <input name="fotoToevo egen" type="checkbox" value="1"
            onclick="Enable Input(this);">

            and your function should be:

            function EnableInput(chk box) {
            var f = chkbox.form;
            f.foto.disabled = !chkbox.checked
            var radioButtons = f.positie;
            if (typeof radioButtons.le ngth == 'undefined') {
            // normalize a single radio button to an array
            radioButtons = [ radioButtons ];
            }
            // handle one or more radio buttons as an array
            for (var i = 0; i < radioButtons.le ngth; i++) {
            radioButtons[i].disabled = !chkbox.checked ;
            }
            }

            Note that you can't simply set the radio button collection disabled=false, you
            must determine if there is more then one radio button and then loop through
            them, changing each disabled property individually.

            Also note that I am using the state of the chkbox (chkbox.checked ) to determine
            what to set the disabled property to, this means if they uncheck the box later
            the various inputs will become disabled again (you may want to reset the checked
            property on each of the radio buttons too, to clear any selection they've made,
            that's optional).

            Of course, now you've created a situation where the inputs are disabled by
            default and enabled using JavaScript. If JavaScript is disabled or unavailable,
            those inputs will _never_ be available. Better to leave all the inputs enabled
            by default, then in <body onload="..."> set them disabled programmaticall y.

            --
            Grant Wagner <gwagner@agrico reunited.com>
            comp.lang.javas cript FAQ - http://jibbering.com/faq


            Comment

            • Mick White

              #7
              Re: enabling form elements

              Harag wrote:
              [color=blue]
              > I'm currently reading Javascript: the Definitive Guide, (Excellent
              > book BTW) and find it very usefull.... That is also pointing out to
              > use all the attributes in lowercase as its HTML. eg[/color]
              [color=blue]
              >
              > onClick, onMouseOver, onMouseOut.
              >
              > is it me or does everyone else get this problem ? is it a setting in
              > NS ?[/color]

              It's you, NS works the same way as IE in this case.
              Mick

              Comment

              • Harag

                #8
                Re: enabling form elements

                On Wed, 28 Jul 2004 17:52:06 GMT, Mick White
                <mwhite13@BOGUS rochester.rr.co m> wrote:
                [color=blue]
                >Harag wrote:
                >[color=green]
                >> I'm currently reading Javascript: the Definitive Guide, (Excellent
                >> book BTW) and find it very usefull.... That is also pointing out to
                >> use all the attributes in lowercase as its HTML. eg[/color]
                >[color=green]
                >>
                >> onClick, onMouseOver, onMouseOut.
                >>
                >> is it me or does everyone else get this problem ? is it a setting in
                >> NS ?[/color]
                >
                >It's you, NS works the same way as IE in this case.
                >Mick[/color]


                Yep, it was, thanks. I changed my code again and it seems to work this
                time. maybe it was a typo last time I tried it.

                Thanks

                AL

                Comment

                Working...