Re: QF element ids generation and setting focus usingjavascript
| From: | Bertrand Mansion | Date: | Mon, 02 Feb 2004 18:53:19 +0000 |
| Subject: | Re: QF element ids generation and setting focus usingjavascript | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10484@lists.php.net to get a copy of this message | ||
<mike.carter@personalmedicaladvisor.co.uk> wrote :
> 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.
It depends on whether you want to do it on the javascript side or on the php
side. If on the php side, then set the id attribute of the element you want
to set focus on, therefore my first reply.
If it is on the javascript side, then read a javascript book ;)
I would use javascript getElementById() but I don't know if it is cross
browser compatible... If you give your form a name, it will also be used for
its id, so no need for form[1].
Bertrand Mansion
Mamasam