Why doesn't this work?! Help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Iver Erling Årva

    #1

    Why doesn't this work?! Help!

    Can anyone please tell me why this doesn't work?

    The sign changes when I hit the button, and I get no error messages, but the
    textarea doesn't disappear/reappear.

    <html>
    <head>
    <title>New Page 1</title>
    </head>

    <body>

    <script type=text/javascript>
    function openNotepad(val u){
    if (valu == "+"){
    document.getEle mentById("NP1") .style.visibili ty="visible";
    document.form.B 1.value="-"
    }
    else {
    document.getEle mentById("NP1") .style.visibili ty="hidden";
    document.form.B 1.value="+"
    }
    }
    </script>

    <form name="form">
    <table>
    <tr>
    <td>
    <input name=B1 type=button value=- onclick=openNot epad(this.value )>
    </td>
    </tr>
    <div id="NP1">
    <tr>
    <td>
    <textarea name="texta01" rows=3 cols=40></textarea>
    </td>
    </tr>
    </div>
    </table>
    </form>
    </body>
    </html>

    Thanks!

    iver@tda.no


  • Grant Wagner

    #2
    Re: Why doesn't this work?! Help!

    "Iver Erling Årva" wrote:
    [color=blue]
    > Can anyone please tell me why this doesn't work?
    >
    > The sign changes when I hit the button, and I get no error messages, but the
    > textarea doesn't disappear/reappear.
    >
    > <html>
    > <head>
    > <title>New Page 1</title>
    > </head>
    >
    > <body>
    >
    > <script type=text/javascript>
    > function openNotepad(val u){
    > if (valu == "+"){
    > document.getEle mentById("NP1") .style.visibili ty="visible";
    > document.form.B 1.value="-"
    > }
    > else {
    > document.getEle mentById("NP1") .style.visibili ty="hidden";
    > document.form.B 1.value="+"
    > }
    > }
    > </script>
    >
    > <form name="form">
    > <table>
    > <tr>
    > <td>
    > <input name=B1 type=button value=- onclick=openNot epad(this.value )>
    > </td>
    > </tr>
    > <div id="NP1">
    > <tr>
    > <td>
    > <textarea name="texta01" rows=3 cols=40></textarea>
    > </td>
    > </tr>
    > </div>
    > </table>
    > </form>
    > </body>
    > </html>
    >
    > Thanks!
    >
    > iver@tda.no[/color]

    <tr></tr> can't be inside a <div>. The only tags that should appear in
    <table></table> are <thead></thead>, <tbody></tbody>, <tfoot></tfoot> and
    <tr></tr>.

    <tr>
    <td><div id="NP1"><texta rea name="texta01" ...></textarea></div></td>
    </tr>

    But you don't need the <div> at all:

    function openNotepad(btn ) {
    var valu = btn.value;
    var f = btn.form;
    var ta = f.elements['texta01'];

    if (ta && ta.style) {

    if (valu == "+") {
    ta.style.visibi lity = 'visible';
    btn.value = "-";
    } else {
    ta.style.visibi lity = 'hidden';
    btn.value = "+";
    }
    }
    }

    <input type="button" value="-" onclick="openNo tepad(this);">

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/a...ence_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • Iver Erling Årva

      #3
      Re: Why doesn't this work?! Help!

      Ok, thanks! This was just an example. What I really want is to hide and
      display entire sections of code. Do I have to enclose the <DIV> tags around
      each and every control to achieve that? I have a bit of code I use to hide
      the contents of a form until all the dropdowns etc.i.e. the entire page has
      been loaded. It is the first statement after the body- and headline tags,
      and I then have a function call in the <BODY ONLOAD statement to call a
      function that svitches the page contents to visible again. I use this in a
      lot of my forms.

      <BODY onLoad="setVisi ble();">

      <!-- Page
      headline -------------------------------------------------------------------
      ------------->
      <H1 ALIGN="CENTER"> ShipAgency - Country Maintenance</H1>

      <!-- Use DIV to hide form while loading-->
      <DIV ID='MyID' style='visibili ty:hidden'>

      <FORM NAME="form" >
      <CENTER>
      <TABLE CELLPADDING="2" >
      <TR>
      <TD><SPAN TITLE="Enter a code and hit the <TAB>-key">
      <DIV ALIGN="RIGHT">< font size="2">*Count ry Code:</font></DIV>
      </TD>
      <td>
      and the rest of the form etc.
      ....
      until the end of the page:

      </TABLE>
      </CENTER>
      </FORM>
      </DIV>
      </BODY>
      </HTML>

      and then the setVisible function (which is held in the page's <HEAD>
      section::

      function setVisible()
      {
      document.getEle mentById("MyID" ).style.visibil ity = "visible";
      }

      Now, the strange thing is that this works just fine with <TR>s, <TD>s and
      whatever I put in there. That is why I didn't understand why the other
      example didn't work (and still don't really) (or alternatively don't
      understant why the above sample work...).

      Confusing!

      IVer@tda.no


      "Grant Wagner" <gwagner@agrico reunited.com> skrev i melding
      news:40B4B111.2 6A52413@agricor eunited.com...[color=blue]
      > "Iver Erling Årva" wrote:
      >[color=green]
      > > Can anyone please tell me why this doesn't work?
      > >
      > > The sign changes when I hit the button, and I get no error messages, but[/color][/color]
      the[color=blue][color=green]
      > > textarea doesn't disappear/reappear.
      > >
      > > <html>
      > > <head>
      > > <title>New Page 1</title>
      > > </head>
      > >
      > > <body>
      > >
      > > <script type=text/javascript>
      > > function openNotepad(val u){
      > > if (valu == "+"){
      > > document.getEle mentById("NP1") .style.visibili ty="visible";
      > > document.form.B 1.value="-"
      > > }
      > > else {
      > > document.getEle mentById("NP1") .style.visibili ty="hidden";
      > > document.form.B 1.value="+"
      > > }
      > > }
      > > </script>
      > >
      > > <form name="form">
      > > <table>
      > > <tr>
      > > <td>
      > > <input name=B1 type=button value=-[/color][/color]
      onclick=openNot epad(this.value )>[color=blue][color=green]
      > > </td>
      > > </tr>
      > > <div id="NP1">
      > > <tr>
      > > <td>
      > > <textarea name="texta01" rows=3 cols=40></textarea>
      > > </td>
      > > </tr>
      > > </div>
      > > </table>
      > > </form>
      > > </body>
      > > </html>
      > >
      > > Thanks!
      > >
      > > iver@tda.no[/color]
      >
      > <tr></tr> can't be inside a <div>. The only tags that should appear in
      > <table></table> are <thead></thead>, <tbody></tbody>, <tfoot></tfoot> and
      > <tr></tr>.
      >
      > <tr>
      > <td><div id="NP1"><texta rea name="texta01" ...></textarea></div></td>
      > </tr>
      >
      > But you don't need the <div> at all:
      >
      > function openNotepad(btn ) {
      > var valu = btn.value;
      > var f = btn.form;
      > var ta = f.elements['texta01'];
      >
      > if (ta && ta.style) {
      >
      > if (valu == "+") {
      > ta.style.visibi lity = 'visible';
      > btn.value = "-";
      > } else {
      > ta.style.visibi lity = 'hidden';
      > btn.value = "+";
      > }
      > }
      > }
      >
      > <input type="button" value="-" onclick="openNo tepad(this);">
      >
      > --
      > | Grant Wagner <gwagner@agrico reunited.com>
      >
      > * Client-side Javascript and Netscape 4 DOM Reference available at:
      > *
      >[/color]
      http://devedge.netscape.com/library/...ce/frames.html[color=blue]
      >
      > * Internet Explorer DOM Reference available at:
      > *
      >[/color]
      http://msdn.microsoft.com/workshop/a...ence_entry.asp[color=blue]
      >
      > * Netscape 6/7 DOM Reference available at:
      > * http://www.mozilla.org/docs/dom/domref/
      > * Tips for upgrading JavaScript for Netscape 7 / Mozilla
      > * http://www.mozilla.org/docs/web-deve...upgrade_2.html
      >
      >[/color]


      Comment

      • bruce

        #4
        Re: Why doesn't this work?! Help!

        "Iver Erling Årva" <iver@tda.no> wrote in message news:<40b4a895$ 1@news.broadpar k.no>...[color=blue]
        > Can anyone please tell me why this doesn't work?
        >
        > The sign changes when I hit the button, and I get no error messages, but the
        > textarea doesn't disappear/reappear.
        >
        > <html>
        > <head>
        > <title>New Page 1</title>
        > </head>
        >
        > <body>
        >
        > <script type=text/javascript>
        > function openNotepad(val u){
        > if (valu == "+"){
        > document.getEle mentById("NP1") .style.visibili ty="visible";
        > document.form.B 1.value="-"
        > }
        > else {
        > document.getEle mentById("NP1") .style.visibili ty="hidden";
        > document.form.B 1.value="+"
        > }
        > }
        > </script>
        >
        > <form name="form">
        > <table>
        > <tr>
        > <td>
        > <input name=B1 type=button value=- onclick=openNot epad(this.value )>
        > </td>
        > </tr>
        > <div id="NP1">
        > <tr>
        > <td>
        > <textarea name="texta01" rows=3 cols=40></textarea>
        > </td>
        > </tr>
        > </div>
        > </table>
        > </form>
        > </body>
        > </html>
        >
        > Thanks!
        >
        > iver@tda.no[/color]



        If you name the <TD> element "NP1", instead of the <div> element,
        it works... I've experienced troubles sometimes putting <DIV> or
        <SPAN> elements in tables.

        Comment

        Working...