473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Choosing visible form elements

Hi all.
I have a javascript function that loops throught all text boxes inside
a form:

var elems = document.formName.elements;
for(i = 0; i < elems.length; i++) {
if(elems[i].type && elems[i].type.toLowerCase()=="text")
do something
}

This way it goes through every single text box in the form.
But in my form structure, some form elements (text boxes included)
are inside invisible divs.
And what I actually want to do, is to check only the text boxes
that are not inside invisible divs.
Is there a way to say in javascript something like:
choose only textbox that is not inside element (div) whose
className='invisible'?

Or maybe I should try a different approach, instead looping through
all form elements?

Thank you very much for your help.
Sorry if I'm asking stupid questions, I'm not very good with
javascript yet.

Anna
Jul 20 '05 #1
1 4349
"Anna" <an**@ubaccess.com> wrote:
And what I actually want to do, is to check only the text boxes
that are not inside invisible divs.
Is there a way to say in javascript something like:
choose only textbox that is not inside element (div) whose
className='invisible'?


function contains(parent,child){
if (parent==child) return true;
var t = child;
if (t && t.parentNode){
if (t.parentNode == parent)
return true;
else
return contains(parent,t.parentNode)
}
return false;
}

var myForm=document.getElementById("your_form_id");
var invisibleDivs=new Array();
var divs=myForm.getElementsByTagName("DIV");
for (var i=0; i<divs.length; i++){
if (divs.item(i).className == "invisible")){
invisibleDivs.push(divs.item(i));
}
}
var textBoxes = myForm.getElementsByTagName("INPUT");
for (var i=0; i<textBoxes.length; i++){
var currentTxtBox = textBoxes.item(i);
if (currentTxtBox.type == "text"){
var good=true;
for (var j=0;j<invisibleDivs.length;j++){
if (contains(invisibleDivs.item(j),currentTextBox)){
good=false;break;
}
}
if (good){
//your code here
}
}
}
Not tested.
Good luck,

Vjekoslav
Jul 20 '05 #2

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

Similar topics

2
by: Stuart Wexler | last post by:
Hi, I have span tag around my form-- which is basically my entire page-- that sets the display to none. I want to, after running through some javascript care of the body onload event, make...
2
by: Mr. Smith | last post by:
Hi. I have a form with three <textarea> and one <input> element. When either of these are changed I want an "Update" button to be visible at the bottom of the form. I've tried this: On every...
2
by: Jon | last post by:
Hi all, I am trying to create a page that contains a number of div elements, with links on the left side of the page allowing the user to select which div to display. Some of the pages contain...
1
by: Dave R | last post by:
Hey everybody! I'm in dire need of some help. I'm trying to loop through all the elements in a form, and determine whether or not the field is visible. Kinda like this: var TForm =...
5
by: Paul E Collins | last post by:
I have a Web form with a number of text boxes. If the user submits the page with some text boxes filled in, those then become plain text (with accompanying <input type="hidden"> fields for when the...
2
by: mark | last post by:
I put this question on a new thread because, in spirit, it is a new question. I apologize that I have difficulty formulating the proper question. My application performs matrix computations on...
2
by: libsfan01 | last post by:
hi! i have written a function to make visible elements with a certain id. however i intended it to be used to make visible multiple elements but it only appears to switch on the first element it...
5
by: Doogie | last post by:
Hi, I am trying to access the visible property of an ASP button inside javascript to no avail. Here's what my button control looks like: <asp:Button id="btnAcceptTrips" name="btnAcceptTrips"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.