473,790 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disabling everything in div section

I have a webpage with a form. Depending on user selections at the top of
the page, the page will disable sections of the form. My plan is to put
each section between a <div></div>. Each section contains some collection
of form elements.

So if the user does not select some criteria, the related section of the
form gets disabled. In a typical Windows type of application these elements
get disabled and greyed out. What's the best way to do this in a webpage?
Can Javascript determine what form elements are in a div section and
disable these elements through a loop for example? I know I can disable
each element if I know its it but is there a way to find out all the IDs of
elements for some div section?

John Dalberg
Mar 2 '06 #1
3 33111
You're going to want to scan the child nodes of the DIV sections. For
instance, if the HTML looks like this:

<div id="div_1">
<input type="text" name="firstname ">
<input type="text" name="lastname" >
<p>ya ya ya</p>
</div>

in the DOM tree the DIV might look like:

DIV
|_input node (<input>)
|_input node (<input>)
|_text node (<p>)

I don't have my JS reference on me, but I'm pretty sure you'll want to
do something like

var div_to_disable = document.getEle mentById( 'div_1' );
var children = div_to_disable. childNodes;
for (var i = 0; i < children.length ; i++)
{
// do stuff here ... such as :
if( children[i].type == 'text' )
children[i].disabled = true;
};

Please be aware, this is really off the cuff and not terribly accurate;
I did more of this a while back. If you're interested and continue to
do this kind of stuff, I'd really recommend getting O'Reilly's
javascript reference. You can do a lot to your DHTML using the DOM
methods. Hopefully this will get you in the right direction.

Mar 2 '06 #2
bobzimuta wrote:
You're going to want to scan the child nodes of the DIV sections. For
instance, if the HTML looks like this:

<div id="div_1">
<input type="text" name="firstname ">
<input type="text" name="lastname" >
<p>ya ya ya</p>
</div>

in the DOM tree the DIV might look like:

DIV
|_input node (<input>)
|_input node (<input>)
|_text node (<p>)

I don't have my JS reference on me, but I'm pretty sure you'll want to
do something like

var div_to_disable = document.getEle mentById( 'div_1' );
var children = div_to_disable. childNodes;


That will only grab the direct child nodes of 'div_1', form controls
nested deeper than that (say inside label elements, tables or divs) will
be descendants of the collection of nodes referenced by 'children'.

An alternative is to use a recursive function to travel down the tree
starting at 'div_to_disable ', or to use getElementsByTa gName('*') to
grab all the elements inside the div (older browsers may not support the
use of '*'). Loop through them and mdofiy the disabled attribute of
relevant elements.
/*
* id - string
* ID of element containing controls to disable/enable
*
* disabled - boolean
* true will disable, false will enable
*/

function setDisabled(id, disabled)
{
if ( !document.getEl ementById
|| !document.getEl ementsByTagName ) return;

var nodesToDisable = {button :'', input :'', optgroup :'',
option :'', select :'', textarea :''};

var node, nodes;
var div = document.getEle mentById(id);
if (!div) return;

nodes = div.getElements ByTagName('*');
if (!nodes) return;

var i = nodes.length;
while (i--){
node = nodes[i];
if ( node.nodeName
&& node.nodeName.t oLowerCase() in nodesToDisable ){
node.disabled = disabled;
}
}
}
Call with:

<input type="button" value="Disable div_1"
onclick="setDis abled('div_1', true)">

<input type="button" value="Enable div_1"
onclick="setDis abled('div_1', false)">
You could also put the names of nodes to disable in a string and test
with a regular expression, or put them in an array and loop through it.
[...]
--
Rob
Mar 3 '06 #3
RobG wrote:
bobzimuta wrote:
var div_to_disable = document.getEle mentById( 'div_1' );
var children = div_to_disable. childNodes;
That will only grab the direct child nodes of 'div_1',


True.
form controls nested deeper than that (say inside label elements, tables
or divs) will be descendants of the collection of nodes referenced by
'children'.


No, they will be descendants of the HTML elements represented by items
(Node object references) of the HTMLCollection object referenced by
'children'.
PointedEars
Mar 3 '06 #4

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

Similar topics

20
2158
by: dukeleto | last post by:
I know this is an annoying thing on some sites. I have set some images in an online gallery to have their own java po up window that is set to be the same size as the image. I would like to set ONLY the pop up window so it does not allow th user to right click. Now I did a search, and found some options, but when you right click it gives the user an annoying pop up saying stuff like "you cant d
5
5056
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main form record. In each page of the tab control, there are three buttons: Add, Update, Delete. Any of these buttons will open another, smaller form to add, update or delete the related data record. Originally, I had placed the smaller form such...
4
2265
by: louise raisbeck | last post by:
Hi there, I have put some web controls, textboxes and drop down lists, in a Panel, so that under a certain condition i can disable all fields for input. I read in Help that disabling a Panel control (enabled=false) will disable all child controls within it - just what i want. but it just doesnt work. panMyPanel.Enabled=false; does absolutely nothing. panMyPanel.Visible=false does hide the whole section, so i know i'm referencing it...
3
1617
by: PB | last post by:
What is the rationalle for disabling JavaScript. AFAIK, the primary reason is for "security purposes" - but what specific kind of threats does the protect against? AND - is the disabling of JavaScript something that is done very much? I know it's impossible to answer that last question definitively - so I'm wondering if it has presented any of you with any real problems in the day-to-day running of your Web applications (i.e. support...
1
3047
by: Matt Van Mater | last post by:
I'm looking to get a little more performance out of my database, and saw in the docs a section about disabling autocommit by using the BEGIN and COMMIT keywords. My problem is this: I enforce unique rows for all data, and occasionally there is an error where I try to insert a duplicate entry. I expect to see these duplicate entries and depend on the DB to enforce the row uniqueness. When I just run the insert statements without the...
9
2175
by: Paul Keegstra | last post by:
Hi, I am currently working on an asp.net 2.0 web site that is a replacement of a classic asp web site. The current web site uses a Commerce Server 2002 database for storing user information. It does not currently use any of the Commerce Server 2002 functionality with the exception of the user authentication features. I have written my replacement application to use a custom login form and custom connection string so that I can use...
2
2444
by: dm1608 | last post by:
I have to issues: 1) Does anyone know of a programmatic way I can disable all textboxes, combo, listboxes, and buttons on a form? 2) What is the best practice for disabling multiple controls on a form. Basically, I need to disable almost everything on a form and re-enable when a particular task is complete. It seems like I duplicate the code over and over in the code... then later when I add a new control, I invariably miss...
1
2195
by: Robert | last post by:
I borrowed one of the forms from the MS Access Solutions database and altered it to fit my needs. The form was the 'EditProducts' form where you select a category from a combo which then populates another combo for products. Then when you select a product, the form displays the info for it. Everything is working well except, with the original, when the form is opened, the focus is on the SelectCategory combo box, while the form elements...
11
12129
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses master pages. I have some pages that must not be cached on the client. In ASP.NET 1.1 I achieved this using metatags: <meta http-equiv="Expires" content="0"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> This tags are part of the <headelement. Sample code that I have seen shows how to add metatags of the form:
0
9512
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,...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
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,...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
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.