getElementByID value

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

    getElementByID value

    I have this tag:

    <span id="member_id"> </span>

    and I want to change the value to "Member"

    why can't I do:

    document.getEle mentByID("membe r_id").value = "Member";

    Any help is appreciated.

    Mike

  • Michael Hill

    #2
    Re: getElementByID value

    or it is:

    document.getEle mentByID("membe r_id").innerHTM L = "Member";

    Michael Hill wrote:
    [color=blue]
    > I have this tag:
    >
    > <span id="member_id"> </span>
    >
    > and I want to change the value to "Member"
    >
    > why can't I do:
    >
    > document.getEle mentByID("membe r_id").value = "Member";
    >
    > Any help is appreciated.
    >
    > Mike[/color]

    Comment

    • Michael Hill

      #3
      Re: getElementByID value

      or it is:

      document.getEle mentByID("membe r_id").innerHTM L = "Member";

      Michael Hill wrote:
      [color=blue]
      > I have this tag:
      >
      > <span id="member_id"> </span>
      >
      > and I want to change the value to "Member"
      >
      > why can't I do:
      >
      > document.getEle mentByID("membe r_id").value = "Member";
      >
      > Any help is appreciated.
      >
      > Mike[/color]

      Comment

      • kaeli

        #4
        Re: getElementByID value

        In article <3FBE3797.10F87 FCC@ram.lmtas.l mco.com>,
        hillmw@ram.lmta s.lmco.com enlightened us with...[color=blue]
        > I have this tag:
        >
        > <span id="member_id"> </span>
        >
        > and I want to change the value to "Member"
        >
        > why can't I do:
        >
        > document.getEle mentByID("membe r_id").value = "Member";
        >[/color]

        There is no value property to a span element.
        I assume you want the text "Member" displayed in that span.

        var e = document.getEle mentById("membe r_id");
        var oTextNode = document.create TextNode("Membe r");
        var oReplaceNode = e.childNodes(0) ;
        oReplaceNode.re placeNode(oText Node);

        You could also use innerHTML, but I have heard it isn't cross-browser
        enough. It would be

        document.getEle mentById("membe r_id").innerHTM L = "Member";

        --
        ~kaeli~
        Why do they sterilize the needles for lethal injections?



        Comment

        • Grant Wagner

          #5
          Re: getElementByID value

          It's getElementById( ), not getElementByID( ), so it would be:

          document.getEle mentById("membe r_id").innerHTM L

          But:

          document.getEle mentById("membe r_id").appendCh ild(document.cr eateTextNode("M ember"));

          is more standards compliant. Please note that the line above is
          only required when initially appending text to the empty span.
          Once the text node exists, you only need to change it's value. If
          you're certain that the span will always only contain a text
          node, you could use something like:

          if (document.getEl ementById("memb er_id").firstCh ild == null) {

          document.getEle mentById("membe r_id").appendCh ild(document.cr eateTextNode("M ember"));

          } else {
          document.getEle mentById("membe r_id").firstChi ld.nodeValue =
          "Something Else";
          }

          Michael Hill wrote:
          [color=blue]
          > or it is:
          >
          > document.getEle mentByID("membe r_id").innerHTM L = "Member";
          >
          > Michael Hill wrote:
          >[color=green]
          > > I have this tag:
          > >
          > > <span id="member_id"> </span>
          > >
          > > and I want to change the value to "Member"
          > >
          > > why can't I do:
          > >
          > > document.getEle mentByID("membe r_id").value = "Member";
          > >
          > > Any help is appreciated.
          > >
          > > Mike[/color][/color]

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

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


          * Internet Explorer DOM Reference available at:
          *
          Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


          * 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

          Working...