Submit article - Debt Consolidation - Sport news - Debt Consolidation - Insurance Quotes

PDA

View Full Version : Need proper syntax


npd1164
Dec 7th 2007, 5:42 am
What's the proper syntax to make this work:

document.myForm.myField.value = newValue;
(Where red portions are variables)

I thought it should be something like:
document.(eval(myForm)).eval(myField).value = newValue;

...but it's not working and cannot seem to find a reference for the proper way to write it. Thanks for any input

hrcerqueira
Dec 7th 2007, 7:49 am
document[myForm][myField].value = newValue;

MMJ
Dec 7th 2007, 8:50 am
I don't think you should use that approach because the name attribute in the form tag isn't valid.

hrcerqueira
Dec 7th 2007, 10:19 am
It isn't in XHTML, that's true. Usually the best thing to do is to call the form fields by theyr id, but there are many people who still does things this way.

npd1164
Dec 7th 2007, 11:29 am
Thanks for the feedback and suggestions. Should've had morning coffee before posting. :o I resolved this by using:

document.getElementById(myField).value = newValue;