Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple DIVs and Forms

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB
I have a form which has multiple DIVs in it. The DIVs can either be 'none' or 'inline' using the style property. I want to be able to find out what elements of the forms are in the DIV that is visible.

ie

<form>

<div id=one style.display='none'><input type=text name=txt1>
<input type=text name=txt2></div>

<div id=two><input type=text name=txt6>
<input type=text name=txt4></div>

<form>

so I would want txt1 and txt2 returned
 
vlitim,

This script should do what you're after:

Code:
<html>
<head>
<script type="text/javascript">
<!--
	function findVisibleElements()
	{
		var formObj = document.forms[0];
		var elementStr = '';
		for (var loop=0; loop<formObj.childNodes.length; loop++) {
			if (formObj.childNodes[loop].tagName == 'DIV' && formObj.childNodes[loop].style.display == 'inline') {
				for (var loop2=0; loop2<formObj.childNodes[loop].childNodes.length; loop2++) {
					if (formObj.childNodes[loop].childNodes[loop2].nodeType != 3) {
						elementStr += formObj.childNodes[loop].childNodes[loop2].name + ', ';
					}
				}
			}
		}
		alert(elementStr);
	}
//-->
</script>
</head>
<body>
	<form>
		<div id="one" style="display:none;"><input type="text" name="txt1">
		<input type="text" name="txt2"></div>

		<div id="two" style="display:inline;"><input type="text" name="txt6">
		<input type="text" name="txt4"></div>

		<input type="button" value="Find Visible Elements" onclick="findVisibleElements();">
	<form>
</body>
</html>

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top