•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,906 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,349 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 5846 | Replies: 2 | Solved
![]() |
•
•
Join Date: Mar 2008
Posts: 117
Reputation:
Rep Power: 1
Solved Threads: 13
I have a couple of div tags inside a form, inside those tags, there are input elements, i would like to know if there is a way to loop over all the input elements that are inside the div tags.
This has to be dynamic as i will not know the exact number of div tags or elements.
Any ideas or directions for me to search.
Thanx.
This has to be dynamic as i will not know the exact number of div tags or elements.
Any ideas or directions for me to search.
Thanx.
You can loop over all the form elements using the
elements attribute of the form or get all the elements under the div and do a selective filtering.<!--
Author: ~s.o.s~
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv"Script-Content-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Example</title>
<script type="text/javascript">
function showOfForm(frm) {
if(!frm || !frm.elements) {
return;
}
var elms = frm.elements;
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
var elm = elms[i];
alert("Type: " + elm.type + "\nName: " +
elm.name + "\nId: " + elm.id);
}
}
function showOfDiv(div) {
if(!div) {
return;
}
div = typeof div === "string" ? document.getElementById(div) : div;
var elms = div.getElementsByTagName("*");
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
var elm = elms[i];
switch(elm.type) {
case "text":
case "textarea":
case "button":
case "reset":
case "submit":
case "file":
case "hidden":
case "password":
case "image":
case "radio":
case "checkbox":
case "select-one":
case "select-multiple":
alert("Type: " + elm.type + "\nName: " +
elm.name + "\nId: " + elm.id);
}
}
}
</script>
</head>
<body>
<form id="frm" name="frm" action="#">
<div id="divOne" style="border: thick solid yellow">
<input type="text" name="txtOne" id="txtOne"><br>
<input type="submit" value="Click me" name="btnOne" id="btnOne"><br>
<input type="radio" name="radGrp1" id="radOne"><br>
<input type="radio" name="radGrp1" id="radTwo"><br>
</div>
<br><br>
<div id="divTwo" style="border: thick solid red">
<select name="selOne" id="selOne" multiple="multiple">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>
<br>
<input type="checkbox" id="chkOne" name="chkGrp1"><br>
<input type="checkbox" id="chkTwo" name="chkGrp1"><br>
</div>
<br><br>
<input type="button" onclick="showOfForm(this.form);"
value="Show form elements" name="btnTwo" id="btnTwo">
<br><br>
<input type="button" onclick="showOfDiv('divTwo');"
value="Show div elements" name="btnThree" id="btnThree">
</form>
</body>
</html> I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Manage Styles... (PHP)
- How to have the div layer center on any browser? (JavaScript / DHTML / AJAX)
- CSS - strech a background image? (Site Layout and Usability)
- javascript:show('newsmsgid'); (JavaScript / DHTML / AJAX)
- A Challenge - Layer/Div Tag related (HTML and CSS)
- Changing text-size ??? (JavaScript / DHTML / AJAX)
- customized right-click menu based on id (JavaScript / DHTML / AJAX)
- Amazing Website Designs - How do they do this? (Site Layout and Usability)
- Problem with <div> height - Controlling flow from center div (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Printing a selected Table
- Next Thread: To hide the url



Linear Mode