I have a requirement in Javascript (using Prototype) to focus the cursor on the first form element in a specific div.
A simple example:
<form id="theForm">
<div id="part1">
<input id="aaa" .../>
<select id="bbb">...</select>
</div>
<div id="part2">
<select id="ccc">...</select>
<input id="ddd" .../>
</div>
</form>
I want to write a Javascript function that takes the name of a div inside a form and focuses the cursor on the first element in that div - for example.
focusOnFirst('part1'); // will put focus on input "aaa"
focusOnFirst('part2'); // will put focus on select "ccc"
I thought I could use a prototype selection method, for example:
$(pDiv).select('input','select',...etc.);
However, this returns an array containing all the inputs, followed by all selected ones, etc. It does not return elements in the order in which they appear in the div. In my example above, this leads to focusing on typing "ddd" rather than choosing "ccc".
Another possibility is the getElements method of the form:
$('theForm').getElements();
, , div. , , - , - div. , , .
- ?