Modifying form values through Javascript

Hi,


I am using Javascript to try to access the values of the elements of a Custom Form I have created.



Typically this value can be recovered / set by the Javascript code … document.formName.elementName.value - where the formName is the Name attribute of the form etc.



Only problem is, it appears that although Matrix assigns an ID element to the form (I managed to get this through the source code, something like form_email_147071, where 147071 is the asset number), it doesn't seem to assign the attribute NAME. I'm not sure why this is, as the actually form elements (ie. question 1, question 2). Have both ID and NAME attributes set. Also, the only way I can get these is through the source code - it is not displayed in the CMS anywhere.



Does anyone know how I can accurately access the form elements in Javascript by using the correct attribute names? How does Matrix assign these values?

Can you use getElementById() to grab the element first and then set the value?


If the form fields each have an ID, why not just access them directly?

    var formValue = document.getElementById('FieldName').value;


Edit: Greg is too quick.

[quote]If the form fields each have an ID, why not just access them directly?

    var formValue = document.getElementById('FieldName').value;


Edit: Greg is too quick.[/quote]

Excellent - that has done the trick.

I guess I just lived up to my forum name...