Re: [QuickForm] Using JavaScript with QF generated Fields ?
| From: | Justin Patrin | Date: | Wed, 08 Dec 2004 21:41:55 +0000 |
| Subject: | Re: [QuickForm] Using JavaScript with QF generated Fields ? | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-16123@lists.php.net to get a copy of this message | ||
On Wed, 08 Dec 2004 22:29:12 +0300, Alexey Borzov <borz_off@cs.msu.su> wrote:
> Hi,
>
> Justin Patrin wrote:
> >>Did you see the word "javascript" in the name of this mailing list? No?
> >>That's because there isn't one!
> >
> > No need to have been so harsh...you could have just responded to his
> > implied question. That would be: "Are the ids set randomly? Is there
> > any way to know what they're going to be?" This *does* have to do with
> > QF as the ids are set by QF.
>
> The right approach would be of course to set the IDs manually in which case they
> are not autogenerated and are known to the script's author...
In other words, use the $attributes parameter to the constructor of
the element, assuming there is one, or use setAttributes() on the
element.
BTW, why is the ID auto-random generated? I understand that some radio
buttons and such could have the same name, but there could be an easy
check for such a thing and a number appended...creating more useful
IDs.
function _generateId()
{
static $idx = array();
if (!$this->getAttribute('id')) {
$name = $this->getAttribute('name');
if (isset($idx[$name])) {
++$idx['name'];
} else {
$idx['name'] = 1;
}
$this->updateAttributes(array('id' => $name . '_' .
$idx[$name]));
}
}
Of course, these ids are more likely to collide with user-created
ones, but they'd be a lot more useful...
>
> >>>"The object does not support that action"
> >>>
> >>>I can't figure out if that is because of an error in the Jscript or some
> >>>Problem according to QF.
> >
> >
> > You may want to use the "correct" way of accessing the form. First of
> > all, give the form a name if you haven't already. Second,
>
> The correct way is using DOM method getElementById() (or maybe
> getElementsByName()), 'name' attribute of <form> tag is not valid XHTML.
>
> > document.forms["formName"].elements["elementName"].checked = true;
> >
> >
>
>
--
Justin Patrin