hide form field

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

    #1

    hide form field

    Hi,

    I had a javscript what does the follow. When a checkbox is yes then i will
    see a form field. When a checkbox is no i dont see the form field.

    Can somehelp me for that script ?

    Greets Wouter


  • Yann-Erwan Perio

    #2
    Re: hide form field

    Wouter wrote:
    [color=blue]
    > I had a javscript what does the follow. When a checkbox is yes then i will
    > see a form field. When a checkbox is no i dont see the form field.[/color]

    <form>
    <input type="checkbox"
    checked="checke d"
    onclick="
    this.form.eleme nts['bar'].style.visibili ty=
    this.checked?'v isible':'hidden ';"[color=blue]
    >[/color]
    <input type="text" name="bar">
    </form>

    Though this doesn't prevent you from server-side checking;-)

    Comment

    • RobG

      #3
      Re: hide form field

      Yann-Erwan Perio wrote:[color=blue]
      > Wouter wrote:
      >[color=green]
      >> I had a javscript what does the follow. When a checkbox is yes then i
      >> will see a form field. When a checkbox is no i dont see the form field.[/color]
      >
      >
      > <form>
      > <input type="checkbox"
      > checked="checke d"
      > onclick="
      > this.form.eleme nts['bar'].style.visibili ty=
      > this.checked?'v isible':'hidden ';"[color=green]
      > >[/color]
      > <input type="text" name="bar">
      > </form>
      >
      > Though this doesn't prevent you from server-side checking;-)[/color]
      I'd also add the following onload:

      <body onload="
      var a=document.getE lementsByTagNam e('form');
      for (var i=0;i<a.length; ++i){a[i].reset();}"[color=blue]
      >[/color]

      Some browsers don't reset forms when you re-load the page, so you may end up with a field displayed that is un-checked. The script above resets all the forms in the page when it's loaded. You may also want to add something that clicks all the "checked" input elements to make sure their onclick event has fired too.

      Last thing: you can also hide stuff using "display: none". The difference is that if something is invisible, it still takes up room on the page. If it's not displayed, it doesn't. See what happens below to the 'X'.

      <head><title>vi sible &amp; display</title></head>

      <body onload="
      var a=document.getE lementsByTagNam e('form');
      for (var i=0;i<a.length; ++i){a[i].reset();
      ">
      <form>
      <table>
      <tr>
      <td>visibilit y method:</td>
      <td>
      <input type="checkbox"
      checked="checke d"
      onclick="
      this.form.eleme nts['bar'].style.visibili ty=
      this.checked?'v isible':'hidden ';"[color=blue]
      >[/color]
      </td>
      <td><input type="text" name="bar">X</td>
      </tr><tr>
      <td>display method:</td>
      <td>
      <input type="checkbox"
      checked="checke d"
      onclick="
      this.form.eleme nts['foobar'].style.display=
      this.checked?'' :'none';"[color=blue]
      >[/color]
      </td>
      <td><input type="text" name="foobar">X </td>
      </tr>
      </table>
      </form>
      </body>
      </html>

      PS. I hope the wrapping/blocking turns out OK, I'm still getting used to this news client...

      Comment

      • RobG

        #4
        Ooops... JS error

        RobG wrote:

        [color=blue]
        > <body onload="
        > var a=document.getE lementsByTagNam e('form');
        > for (var i=0;i<a.length; ++i){a[i].reset();[/color]

        Arggghhh! The closing "}" is missing from the onload in the lower code block.... use the onload from the top and all will be sweet (or just delete the leading "{").

        Sorry.

        Comment

        • Yann-Erwan Perio

          #5
          Re: hide form field

          RobG wrote:
          [color=blue]
          > Last thing: you can also hide stuff using "display: none". The
          > difference is that if something is invisible, it still takes up room on
          > the page. If it's not displayed, it doesn't. See what happens below to
          > the 'X'.[/color]

          Good point, this might indeed be preferable in some situations.
          [color=blue]
          > PS. I hope the wrapping/blocking turns out OK, I'm still getting used
          > to this news client...[/color]

          It seems fine here, however the line length wasn't wrapped when I
          checked Google's archives, so it could display the same in other
          newsreaders (maybe due to your charset encoding?).

          <URL:http://groups.google.c om/groups?selm=MwN 1d.1111%24aA.40 558%40news.optu s.net.au>

          Since you seem interested on this topic, I'd like to suggest the
          following resource, which goes into details into c.l.j posting standards:

          <URL:http://www.jibbering.c om/faq/faq_notes/pots1.html>

          You can also use alt.test to post test messages, playing with signatures
          etc. Welcome on Usenet!


          Regards,
          Yep.

          Comment

          • Wouter

            #6
            Re: Ooops... JS error

            Tanks that is wgere i`m looking for!

            Greets Wouter

            "RobG" <rgqld@iinet.ne t.auau> schreef in bericht
            news:oDN1d.1112 $aA.40443@news. optus.net.au...[color=blue]
            > RobG wrote:
            >
            >[color=green]
            >> <body onload="
            >> var a=document.getE lementsByTagNam e('form');
            >> for (var i=0;i<a.length; ++i){a[i].reset();[/color]
            >
            > Arggghhh! The closing "}" is missing from the onload in the lower code
            > block.... use the onload from the top and all will be sweet (or just
            > delete the leading "{").
            >
            > Sorry.[/color]


            Comment

            Working...