Forum OpenACS Development: Re: Any reason to not add form_id to widget HTML ids?

Collapse
Posted by Antonio Pisano on
This could make sense, but given the age of current behavior I am sure it would break some pages around.

One convenient way we use to access specific form fields by javascript, which is very similar to a getElementById one-liner is:

var formField = document.<formName>.<fieldName>;

AFAIK this is portable and wouldn't require any change in field naming.

Collapse
Posted by Dave Bauer on
Thanks,

I like that technique. Very simple. I'll have to see if I can migrate my code to use that. One issue is that you can get duplicate element ids if you use multiple forms and generic element names like "date" etc. You could also have an issue where you use multiple instances of the same form, but it might work well for existing OpenACS code without requiring any changes, and the other problems can be addresses in locally created code.

Collapse
Posted by Antonio Pisano on
I made a brief check on Chrome and Firefox (linux). That technique goes with the "name" attribute, rather than with the "id". I wasn't sure about that because we always put both with the same value.

In theory, you could of course have multiple forms called with the same name, but in practice this shouldn't happen, at least in my opinion. Field names can recurr often, but formName + fieldName combined are usually unique in a page, so that dot notation should be safe enough.