change HTML label on the fly

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

    change HTML label on the fly

    I want to change the label on the fly (when the user click the
    checkbox), but my attempt
    InputForm.lataL bl.value = "LATA * "; didn't work. Here's my code, any
    ideas?
    thanks !!!


    <html>
    <script type="text/javascript">
    function ig_onchange()
    { if (InputForm.ig.c hecked == true)
    { InputForm.btn.v alue = "Populate";
    InputForm.lataL bl.value = "LATA * "; //DOES NOT WORK!!!
    }
    else
    {
    InputForm.btn.v alue = "Validate";
    }
    }
    </script>
    <body>
    <form name="InputForm ">
    <P><input type="checkbox" name="ig" onclick="ig_onc hange()">
    <P><label for="lataLbl">L ATA</label>
    <P><input type="button" name="btn" value="Validate ">
    </form>
    </body>
    </html>
  • G Roydor

    #2
    Re: change HTML label on the fly

    Voyez innerhtml

    GR

    Matt a écrit:[color=blue]
    > I want to change the label on the fly (when the user click the
    > checkbox), but my attempt
    > InputForm.lataL bl.value = "LATA * "; didn't work. Here's my code, any
    > ideas?
    > thanks !!!
    >
    >
    > <html>
    > <script type="text/javascript">
    > function ig_onchange()
    > { if (InputForm.ig.c hecked == true)
    > { InputForm.btn.v alue = "Populate";
    > InputForm.lataL bl.value = "LATA * "; //DOES NOT WORK!!!
    > }
    > else
    > {
    > InputForm.btn.v alue = "Validate";
    > }
    > }
    > </script>
    > <body>
    > <form name="InputForm ">
    > <P><input type="checkbox" name="ig" onclick="ig_onc hange()">
    > <P><label for="lataLbl">L ATA</label>
    > <P><input type="button" name="btn" value="Validate ">
    > </form>
    > </body>
    > </html>[/color]

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: change HTML label on the fly

      jrefactors@hotm ail.com (Matt) writes:
      [color=blue]
      > I want to change the label on the fly (when the user click the
      > checkbox), but my attempt
      > InputForm.lataL bl.value = "LATA * "; didn't work.[/color]

      No, for many reasons.

      First of all, referring to the form by using its name as a variable
      won't work in most browsers (it will work in IE).

      The label is not a form control, so it's not a property of the form.

      The content of a label is normal HTML, so you can't refer to it
      as a simple property named "value".
      [color=blue]
      > Here's my code, any ideas?[/color]

      Try this:
      ---
      <!DOCTYPE html PUBLIC "-//W3C/HTML 4.01//EN">
      <html>
      <title>Title element is required, as is DOCTYPE!</title>
      <script type="text/javascript">
      function ig_onchange() {
      var form = document.forms['InputForm'].elements;
      if (form.ig.checke d) {
      form.btn.value = "Populate";
      document.getEle mentById("label Id").firstChild .nodeValue="LAT A *";
      } else {
      form.btn.value = "Validate";
      }
      }
      </script>
      <body>
      <form name="InputForm " id="InputForm" >
      <p><input type="checkbox" name="ig" onclick="ig_onc hange()"></p>
      <p><label id="labelId" for="buttonId"> LATA</label></p>
      <p><input type="button" id="buttonId" name="btn" value="Validate "></p>
      </form>
      </body>
      </html>
      ---

      It only works in modern browsers. There are a few older browser
      (especially IE 4) that can be made to work with some extra code.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Jeff Thies

        #4
        Re: change HTML label on the fly

        Don't multi post. It annoys the regulars when found out.

        I just read this in alt.html.

        Cross post if you must.

        Jeff


        "Matt" <jrefactors@hot mail.com> wrote in message
        news:ba8a039e.0 406251026.68e1e 19c@posting.goo gle.com...[color=blue]
        > I want to change the label on the fly (when the user click the
        > checkbox), but my attempt
        > InputForm.lataL bl.value = "LATA * "; didn't work. Here's my code, any
        > ideas?
        > thanks !!!
        >
        >
        > <html>
        > <script type="text/javascript">
        > function ig_onchange()
        > { if (InputForm.ig.c hecked == true)
        > { InputForm.btn.v alue = "Populate";
        > InputForm.lataL bl.value = "LATA * "; file://DOES NOT WORK!!!
        > }
        > else
        > {
        > InputForm.btn.v alue = "Validate";
        > }
        > }
        > </script>
        > <body>
        > <form name="InputForm ">
        > <P><input type="checkbox" name="ig" onclick="ig_onc hange()">
        > <P><label for="lataLbl">L ATA</label>
        > <P><input type="button" name="btn" value="Validate ">
        > </form>
        > </body>
        > </html>[/color]


        Comment

        Working...