DOM Question

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

    DOM Question

    Greetings,

    What's the text between checkbox <INPUT> tags in DOM speak?
    INPUTobj.childN odes returns true; however, firstChild returns NULL!?

    e.g.: <INPUT type="checkbox" name="somename[]" id="id" value="1">text to
    be changed on client event</INPUT>

    Any pointers greatly appreciated.

    Mike
  • Richard Cornford

    #2
    Re: DOM Question

    Michael Ruebner wrote:[color=blue]
    > What's the text between checkbox <INPUT> tags in DOM speak?[/color]

    That would depend on the HTML.
    [color=blue]
    > INPUTobj.childN odes returns true;[/color]

    An empty childNodes collection is still a collection and so still an
    object (it will type-convert to boolean true).
    [color=blue]
    > however, firstChild returns NULL!?[/color]

    INPUT elements don't have content so they would have null firstChild
    properties.
    [color=blue]
    > e.g.: <INPUT type="checkbox" name="somename[]" id="id" value="1">
    > text to be changed on client event</INPUT>[/color]

    That is invalid mark-up as INPUT elements cannot have contents. Browser
    error-correction would probably make the text a nextSibling of the input
    element, but with invalid mark-up that cannot be guaranteed.
    [color=blue]
    > Any pointers greatly appreciated.[/color]

    If you want any consistent behaviour when scripting start with formally
    valid HTML.

    Richard.


    Comment

    • RobG

      #3
      Re: DOM Question

      Michael Ruebner wrote:[color=blue]
      > Greetings,
      >
      > What's the text between checkbox <INPUT> tags in DOM speak?
      > INPUTobj.childN odes returns true; however, firstChild returns NULL!?
      >
      > e.g.: <INPUT type="checkbox" name="somename[]" id="id" value="1">text to
      > be changed on client event</INPUT>[/color]

      As Richard says above, text placed in an <input> is a
      sibling of the input and is (in Firefox) given a text node
      type 3.

      To turn it into an element (type 1) that you can
      manipulate, put it inside an element tag, such as <p>
      <span> <div> or similar valid HTML tags. It will be an
      "official" sibling of the input.

      Fred.

      Comment

      • Michael Winter

        #4
        Re: DOM Question

        On Mon, 04 Oct 2004 22:39:04 GMT, RobG <rgqld@iinet.ne t.auau> wrote:

        [snip]
        [color=blue]
        > To turn it into an element (type 1) that you can
        > manipulate, put it inside an element tag, such as <p>
        > <span> <div> or similar valid HTML tags. It will be an
        > "official" sibling of the input.[/color]

        As the text probably qualifies as a label, the LABEL element would be the
        best to use:

        <label for="myInput">< input id="myInput" type="checkbox" ...>
        Your text here</label>

        All DOM-supporting browsers should access that label text with:

        inputObj.nextSi bling.data

        (Verified with the latest versions of Opera, IE, Mozilla, Netscape, and
        Firefox)

        When you change the value, remember to add a space before the text so that
        it doesn't appear flush next to the checkbox.

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Michael Ruebner

          #5
          Re: DOM Question

          Mike,
          [color=blue]
          > As the text probably qualifies as a label, the LABEL element would be
          > the best to use:[/color]

          I settled for a SPAN following the closing <INPUT> tag. Thanks a lot for
          your, Rob's, and Richard's input [sic]! I guess Richard is right:
          sometimes it pays to use valid HTML....

          Bests

          Mike

          Comment

          Working...