RE: [PEAR] QF element ids generation and setting focus usingjavascript
| From: | Mike Carter | Date: | Mon, 02 Feb 2004 17:21:39 +0000 |
| Subject: | RE: [PEAR] QF element ids generation and setting focus usingjavascript | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10482@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Bertrand Mansion [mailto:bmansion@mamasam.com]
>
> <mike.carter@personalmedicaladvisor.co.uk> wrote :
>
> > Hi,
> >
> > Could somebody explain to me how the element ids are
> generated in QF.
> > They are in the form id="qf_f77d61".
> >
> > I would like to write some javascript which is called at
> the end of the
> > renderer template. The javascript will place the focus in
> the first element
> > that can handle the focus() method.
> >
> > Using something very simple like
> document.forms[0].elements[0].focus();
> > does't work because hidden elements are placed before
> 'normal' elements in a
> > quickform.
> >
> > Has anybody already done this in javascript?
>
> id is an attribute...
That wasn't quite the information I was after.
I've started writing a small piece of javascript which aims to loop through
quickform elements and find the first visible element which has had nothing
input in to it (no value set).
<script type="text/javascript" language="JavaScript" defer><!--
for(elementid = 0; elementid < document.forms[1].elements.length;
elementid++) {
thiselement = document.forms[1].elements[elementid];
// --- Find first form element that is visible and has no value
if(thiselement.type != 'hidden' && !thiselement.value) {
thiselement.focus();
break;
}
}
//--></script>
The above finds the first element fine, but doesn't always give it focus()
for some reason.
My original question was regarding a way of working out the first quickform
id element so that I could do away with the loop maybe.
My page contains multiple forms, I cannot think of a way to check if a form
is a quickform generated one or not. This would make my document.forms[1]
assumption safer.
Regards,
Mike c.