469,909 Members | 1,617 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 4210
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stuart Wexler | last post: by
1 post views Thread by Dave R | last post: by
5 posts views Thread by Paul E Collins | last post: by
2 posts views Thread by libsfan01 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.