470,616 Members | 2,189 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,616 developers. It's quick & easy.

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="checkNextEnabled()" id=manSPAN >

<tr>
<td>
<input type=radio name=uid value=manualUID>
</td>
<td>Manual Entry
</td>
<td>
<INPUT type="text" style="width:100%" name=txtmanualuid>
</td>
</tr>

</span>
Jul 23 '05 #1
4 5414
On 26 Apr 2004 02:11:33 -0700, blueey <gu********@yahoo.com> wrote:
I have a span element somewhere somewhere in between my table.
That's invalid HTML.
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.
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.org/>
Also how do i check that the element that has been clicked is the span
element?
Check the event's target. IE-like browsers will use event.srcElement and
Netscape-like (and DOM conforming) browsers will use event.target.
I cant seem to use the type attribute as it gives me error.
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?
it seems simple enough doesnt it?


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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2


blueey wrote:
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="checkNextEnabled()" id=manSPAN >

<tr>
<td>
<input type=radio name=uid value=manualUID>
</td>
<td>Manual Entry
</td>
<td>
<INPUT type="text" style="width:100%" name=txtmanualuid>
</td>
</tr>

</span>


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
http://JavaScript.FAQTs.com/

Jul 23 '05 #3
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 <ma*******@yahoo.de> wrote in message news:<40********@olaf.komtel.net>...
blueey wrote:
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="checkNextEnabled()" id=manSPAN >

<tr>
<td>
<input type=radio name=uid value=manualUID>
</td>
<td>Manual Entry
</td>
<td>
<INPUT type="text" style="width:100%" name=txtmanualuid>
</td>
</tr>

</span>


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

Jul 23 '05 #4


blueey wrote:
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.


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
http://JavaScript.FAQTs.com/

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by David | last post: by
1 post views Thread by assgar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.