Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Choosing visible form elements

Reply
Thread Tools

Choosing visible form elements

 
 
Anna
Guest
Posts: n/a
 
      11-18-2003
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
 
Reply With Quote
 
 
 
 
Vjekoslav Begovic
Guest
Posts: n/a
 
      11-18-2003
"Anna" <> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a hyperlink Visible or not visible in DataList Patrick Olurotimi Ige ASP .Net 7 06-15-2005 12:01 PM
Sections visible and not visible tshad ASP .Net 4 01-31-2005 09:30 PM
button visible/not visible tshad ASP .Net 6 10-28-2004 10:02 PM
Visible button after update in form elements Mr. Smith ASP General 2 10-20-2004 10:51 AM
Panel.Visible = True also make child controls visible. spamfurnace ASP .Net 1 05-24-2004 03:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57