Looping Through the span element

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

    Looping Through the span element

    I have a span element somewhere somewhere in between my table. How do
    i loop through the elemenst (namely in this case radio and text) and
    retreive the values of the child elements and it's type. Also how do i
    check that the element that has been clicked is the span element?I
    cant seem to use the type attribute as it gives me error. it seems
    simple enough doesnt it?






    <span value=span onClick="checkN extEnabled()" id=manSPAN >

    <tr>
    <td>
    <input type=radio name=uid value=manualUID >
    </td>
    <td>Manual Entry
    </td>
    <td>
    <INPUT type="text" style="width:10 0%" name=txtmanualu id>
    </td>
    </tr>

    </span>
  • Michael Winter

    #2
    Re: Looping Through the span element

    On 26 Apr 2004 02:11:33 -0700, blueey <gunaselanV@yah oo.com> wrote:
    [color=blue]
    > I have a span element somewhere somewhere in between my table.[/color]

    That's invalid HTML.
    [color=blue]
    > How do i loop through the elemenst (namely in this case radio and text)
    > and retreive the values of the child elements and it's type.[/color]

    You shouldn't try. All browsers should try and error-correct your HTML to
    something resembling valid HTML. However, all browsers are likely to
    produce different results, so walking the tree might yield strange
    behaviour. Write valid HTML and validate your document before trying to
    script it. See

    <URL:http://validator.w3.or g/>
    [color=blue]
    > Also how do i check that the element that has been clicked is the span
    > element?[/color]

    Check the event's target. IE-like browsers will use event.srcElemen t and
    Netscape-like (and DOM conforming) browsers will use event.target.
    [color=blue]
    > I cant seem to use the type attribute as it gives me error.[/color]

    You haven't posted your code, so ask yourself these questions

    1) Do you check that your references are valid (not undefined or null)?
    2) Is the object a form control?
    [color=blue]
    > it seems simple enough doesnt it?[/color]

    Yes, but you're making life very difficult for yourself. First, why aren't
    you using the table row as a container. Using SPAN as you do is grossly
    illegal:

    1) Only table-related elements can exist as children of a TABLE or table
    section elements.
    2) In-line elements cannot contain block elements
    3) SPAN elements don't have value attributes

    [snipped HTML]

    Hope that helps,
    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Martin Honnen

      #3
      Re: Looping Through the span element



      blueey wrote:
      [color=blue]
      > I have a span element somewhere somewhere in between my table. How do
      > i loop through the elemenst (namely in this case radio and text) and
      > retreive the values of the child elements and it's type. Also how do i
      > check that the element that has been clicked is the span element?I
      > cant seem to use the type attribute as it gives me error. it seems
      > simple enough doesnt it?
      >
      >
      > <span value=span onClick="checkN extEnabled()" id=manSPAN >
      >
      > <tr>
      > <td>
      > <input type=radio name=uid value=manualUID >
      > </td>
      > <td>Manual Entry
      > </td>
      > <td>
      > <INPUT type="text" style="width:10 0%" name=txtmanualu id>
      > </td>
      > </tr>
      >
      > </span>[/color]

      A <span> containing a <tr> element? That looks very odd, <tr> elements
      should sit in <tbody>, <thead>, <tfoot> elements or in <table> elements.
      Fix your markup first then look at DOM scripting otherwise you rely on
      the HTML parser of the browser fixing your markup
      --

      Martin Honnen


      Comment

      • blueey

        #4
        Re: Looping Through the span element

        Thanks guys, will fix the HTML. But i was just trying to find a way to
        logically group a number of elements. Not really still sure what would
        be the best way. Say if i have a radio and text box in a table and i
        need to identify them as a group of elements. What would be the best
        way.

        Martin Honnen <mahotrash@yaho o.de> wrote in message news:<408cec1f$ 1@olaf.komtel.n et>...[color=blue]
        > blueey wrote:
        >[color=green]
        > > I have a span element somewhere somewhere in between my table. How do
        > > i loop through the elemenst (namely in this case radio and text) and
        > > retreive the values of the child elements and it's type. Also how do i
        > > check that the element that has been clicked is the span element?I
        > > cant seem to use the type attribute as it gives me error. it seems
        > > simple enough doesnt it?
        > >
        > >
        > > <span value=span onClick="checkN extEnabled()" id=manSPAN >
        > >
        > > <tr>
        > > <td>
        > > <input type=radio name=uid value=manualUID >
        > > </td>
        > > <td>Manual Entry
        > > </td>
        > > <td>
        > > <INPUT type="text" style="width:10 0%" name=txtmanualu id>
        > > </td>
        > > </tr>
        > >
        > > </span>[/color]
        >
        > A <span> containing a <tr> element? That looks very odd, <tr> elements
        > should sit in <tbody>, <thead>, <tfoot> elements or in <table> elements.
        > Fix your markup first then look at DOM scripting otherwise you rely on
        > the HTML parser of the browser fixing your markup[/color]

        Comment

        • Martin Honnen

          #5
          Re: Looping Through the span element



          blueey wrote:
          [color=blue]
          > Thanks guys, will fix the HTML. But i was just trying to find a way to
          > logically group a number of elements. Not really still sure what would
          > be the best way. Say if i have a radio and text box in a table and i
          > need to identify them as a group of elements. What would be the best
          > way.[/color]

          If you want to group a couple of table rows as a table section then use
          a <tbody> element e.g.
          <table>
          <tbody>
          <tr>....</tr>
          <tr>....</tr>
          <tr>....</tr>
          </tbody>
          <tbody>
          <tr>....</tr>
          <tr>....</tr>
          </tbody>
          </table>

          As for grouping form controls HTML offers the <fieldset> element for
          that although you might not be able to use it in a meaningful and
          structurally correct way if your form controls sit in different table cells.
          --

          Martin Honnen


          Comment

          Working...