473,791 Members | 2,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct Way to Reference Children of a DIV?

What is the correct way to find all the form elements in a particular
div? I'd like to be able to loop through them and disable them. For
example:

<form>
<div id="div1">
<input type=text name="a">
<input type=text name="b">
</div>

<div id="div2">
<input type=text name="c">
<input type=text name="d">
</div>

</form>

I'd like to be able to pass "div1" to a function and have it disable
text boxes a and b.

Thanks in advance for any help or ideas.

Nov 3 '05 #1
17 2417

er*******@gmail .com wrote:
What is the correct way to find all the form elements in a particular
div? I'd like to be able to loop through them and disable them. For
example:

<form>
<div id="div1">
<input type=text name="a">
<input type=text name="b">
</div>

<div id="div2">
<input type=text name="c">
<input type=text name="d">
</div>

</form>

I'd like to be able to pass "div1" to a function and have it disable
text boxes a and b.

Thanks in advance for any help or ideas.


One option is to use the standard DOM methods:-

var eDIV=document.g etElementById(" div1");
var cINPUTS=eDIV.ge tElementsByTagN ame("INPUT");

Julian

Nov 3 '05 #2


er*******@gmail .com wrote:

<div id="div1">
<input type=text name="a">
<input type=text name="b">
</div> I'd like to be able to pass "div1" to a function and have it disable
text boxes a and b.


With the W3C DOM (implemented in IE 5 and later, Netscape 6 and later,
Mozilla 1.0 and later, Opera 7 and later and other newer browsers like
Safari) every element has a method
getElementsByTa gName
to find descendant elements by their tag name thus if you have an
element object then
elementObject.g etElementsByTag Name('input')
return a node list with all descendant elements with the tagName input.
So you can loop through that node list e.g.
var inputElements = elementObject.g etElementsByTag Name('input');
for (var i = 0; l = inputElements.l ength; i < l; i++) {
inputsElements[i].disabled = true;
}

Of course there are other form controls like textarea or select elements
for which you would need to look with additional calls to
getElementsByTa gName.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 3 '05 #3
VK

er*******@gmail .com wrote:
What is the correct way to find all the form elements in a particular
div? I'd like to be able to loop through them and disable them. For
example:

<form>
<div id="div1">
<input type=text name="a">
<input type=text name="b">
</div>

<div id="div2">
<input type=text name="c">
<input type=text name="d">
</div>

</form>

I'd like to be able to pass "div1" to a function and have it disable
text boxes a and b.

Thanks in advance for any help or ideas.

I think you may start from the proper form layout. Form elements and
DIV's are not in direct parent-child relations: they just can be forced
to overlap each other like in your case. It may hurt you during dynamic
form manipulations. The rest as suggested by the previous poster.

<html>
<head>
<title>Form</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script type="text/javascript">
function getBlock1() {
var d = document.getEle mentById('fs1') ;
var a =d.getElementsB yTagName('INPUT ');
// ...
}
</script>

</head>

<body onload="getBloc k1()">

<form>
<fieldset id="fs1">
<legend>Block 1</legend>
<input type=text name="a">
<input type=text name="b">
</fieldset>
<fieldset id="fs2">
<legend>Block 2</legend>
<input type=text name="c">
<input type=text name="d">
</fieldset>
</form>

</body>
</html>

Nov 3 '05 #4
Thanks to everyone who has helped me. Here's something I don't
understand:

VK wrote:

I think you may start from the proper form layout. Form elements and
DIV's are not in direct parent-child relations: they just can be forced
to overlap each other like in your case.


Wait a minute! Any large form is going to *have* to be broken up by
divs, spans, tables, etc. I can't believe that's wrong! It's
practically required!

Are you saying that you never have anything but form elements between
the begin and end form tags? How do you, for example, line up a bunch
of checkboxes into columns? A few divs, floated right, is perfect for
something like that.

it's obvious you know what you're talking about so I'm not arguing.
I'm just kind of blown away by this.

Nov 3 '05 #5
VK wrote:
er*******@gmail .com wrote: <snip>
<form>
<div id="div1">
<input type=text name="a">
<input type=text name="b">
</div>

<div id="div2">
<input type=text name="c">
<input type=text name="d">
</div>

</form>

<snip> I think you may start from the proper form layout. Form
elements and DIV's are not in direct parent-child relations:
they just can be forced to overlap each other like in your
case. It may hurt you during dynamic form manipulations.
Utter nonsense. That HTML is completely fine and valid, even by the
strict DTD.
The rest as suggested by the previous poster.

<snip>

So another VK 'contribution' that can only hinder the OP's
understanding.

Richard.
Nov 3 '05 #6
er*******@gmail .com wrote:
VK wrote:
I think ...
<snip>
it's obvious you know what you're talking about
Martin Honnen knows what he is talking about and I suspect that Julian
Turner knows enough not to talk about what he doesn't know, but VK is a
very different story. In statistical terms you would be better off (more
often than not correct) assuming that anything VK says is false,
inadequate or misconceived.
so I'm not arguing.
I'm just kind of blown away by this.


Feel free to argue, is it were true there would be something to back it
up.

Richard.
Nov 3 '05 #7
VK

er*******@gmail .com wrote:
Thanks to everyone who has helped me. Here's something I don't
understand:
VK wrote:

I think you may start from the proper form layout. Form elements and
DIV's are not in direct parent-child relations: they just can be forced
to overlap each other like in your case.
Wait a minute! Any large form is going to *have* to be broken up by
divs, spans, tables, etc. I can't believe that's wrong! It's
practically required!

Are you saying that you never have anything but form elements between
the begin and end form tags? How do you, for example, line up a bunch
of checkboxes into columns? A few divs, floated right, is perfect for
something like that.

it's obvious you know what you're talking about so I'm not arguing.
I'm just kind of blown away by this.


Don't get so exaggerated. My suggestion was about the *posted code*
where I see two blocks of the same form which you're trying to separate
visually(?) and functionally(?) .

The golden rule is to try to solve the problem in easy and possibly
correct way first.
If not - then try to solve it in a not so easy and possibly
non-standard way.
For the posted code table layout was not requested, so internal
subdivisions using <fieldset> were totally logical *and* more correct
then <div> because <fieldset> *is* direct form's child and direct
parent to its elements. Just check and compare myDiv.form and
myFieldset.form property.
Naturally in design one *has* to use tables for nearly any form for
nice looking scalable layout. I'm personally using it since 1997and
over the passed years I had to place form elements to the most
fantastic places - not only tables. :-)

Richard Cornford wrote: ... some offensive off-topic stuff I'm not going to waste my time to comment on.


Nov 3 '05 #8
"VK" <sc**********@y ahoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .

er*******@gmail .com wrote:
Thanks to everyone who has helped me. Here's something I don't
understand:
VK wrote:
>
> I think you may start from the proper form layout. Form elements and

<snipped/>
Naturally in design one *has* to use tables for nearly any form for nice looking scalable layout. I'm personally using it since 1997and
over the passed years I had to place form elements to the most
fantastic places - not only tables. :-)


Naturally, you meant to say:
"...in design one *has* to use divs/spans for nearly any form
for nice looking scaleable layout..."?

Tables are in a semantic document for presenting tabular data,
not for positioning elements.

For that, we have css.

--
Dag.

Nov 3 '05 #9
VK
> "VK" <sc**********@y ahoo.com> wrote in message
Naturally in design one *has* to use tables for nearly any form for
nice looking scalable layout. I'm personally using it since 1997and
over the passed years I had to place form elements to the most
fantastic places - not only tables. :-)

Dag Sunde wrote: Naturally, you meant to say:
"...in design one *has* to use divs/spans for nearly any form
for nice looking scaleable layout..."?

Tables are in a semantic document for presenting tabular data,
not for positioning elements.

For that, we have css.


CSS is not suitable for scaleable layout, this path has been explored
throughout during 4th versions on positioned elements and on the Java
1.x GridBagLayout
It failed to work and abandonned now in favor of the original
"invisible table" technique.
When did you last time visited the Web?
But it doesn't mean that we need to use table *every single time* some
positionning is needed.

Nov 3 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1605
by: Raghuraman | last post by:
Hi, I have some tables which have references between them. If i delete the reors in the child tables , since it references the column of the parent , i get error msg in my front end (quite natural). do u tell me how to delete the child table records with out affecting the relation ships or can recreate the relations with out affecting my data & structure and the constraints.
2
1589
by: Good Enchiladas | last post by:
While building on a class library for an object model, I get the above error message. The steps to recreate the problem are as follows: 1. Build a RootLevel.dll containing only this code: Public Class Root End Class
5
2999
by: JC | last post by:
hi all First of all, sorry for my (bad) english, I have a javascript: <script type="text/javascript"> <!-- function gointo(td,color){td.style.cursor='default';td.bgColor=color;} function gooutoff(td,color){td.style.cursor='default';td.bgColor=color;}
1
3433
by: Guogang | last post by:
Hi, I have a tree structure in C# with pointer to children and parent. This will form a circular reference. My question: will this kind of circular reference affect garbage collection (parent has references to children, and children have references to parent. such that none of them can be GC)? If yes, how can I avoid it? Thanks,
3
752
by: TN Bella | last post by:
I can't figure this out and I need some help...please! Object reference not set to an instance of an object. 'Insert data into the account table Sub doInsert2(Source as Object, E as EventArgs) Dim strConn as string = "server=abcdef;database=a_;trusted_connection=true" Dim Mysql1 as string Dim MyConn1 As New SqlConnection(strConn) MySql1 = "INSERT INTO
2
2677
by: Martin Ortiz | last post by:
Ugh.... All classes are copy by reference, even if you use "ByVal" and NOT "ByRef" it's still a copy by reference. Of course, as a consequence, if you change any values of the object you passed in, the original object is affected. I expect this with arrays, but not with single objects being passed "ByVal" to functions.... Is there a sane to get "ByVal" passing of parameters? (copying fields is not
2
1444
by: Al in Dallas | last post by:
I made the mistake of creating an instance of a widget and assigning it to a name I'd already used. Now, if I use root.children or root.slaves(), I can see the "lost" widget, but can I do anything else with the string of numbers that shows up when I use root.children? I'd like to destory the widget, for example. it would be even better if I could create a new name and have it reference the "lost" widget. Of course, I can just kill my...
5
5071
by: RioRanchoMan | last post by:
I have a forum table where the field Forum_ID of the first thread corresponds to itself in the field Forum_Ancestor, and 0 (zero) for the field Forum_Parent when it is the first topic in a thread: Example of first topic in thread values ============================================= Forum_ID=13 (topic) Forum_Parent=0 Forum_Ancestor=13
6
2649
by: stephen.cunliffe | last post by:
Hi, I'm looking for opinion/facts/arguments on the correct nesting of UL, OL, & LI elements. For example, this is what I want (unordered list): * Item 1 * Item 2 * Item 3
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.