I search for an answer and while I found discusions on the issue I did not see any solutions.

What I want to do is fill in a HTML form field from javascript. I can do this with hand written html, but can not fiind the correct way to refere to fields by name when they follow the pattern used by the form functions (edit[name] or edit[name][]).

I want to have the onclick handler to a button call a function with a reference to the field, something like function(this.form.field_name); My attempts so far though to match field_name with the name generated by the Drupal form functions have produced javascript errors.

Does any one have a solution for this?

Thanks
Steve

Comments

webgeer’s picture

Did you ever solve this?

Thanks

webgeer’s picture

By looking at some other javascript based modules I was able to figure out that you can do something like:

 var areas = document.getElementsByTagName("input");
                for (var i=0; i<areas.length; i++)  {
                        if (areas[i].name.match("name"))  {
                                namefield = areas[i];
                        }                       
                }

you can get a pointer to the form element that has the name edit[name].

nevets’s picture

I will need to try that out and see if it does the trick.

MAYC’s picture

You can use document.getElementById('edit-name') where name is the form item name. Id's generated by drupal form functions take this form: edit-name

MAYC