How do I concatenate a javascript argument with a field name stub to identify an html field on my form? The argument is the current row of a query passed from coldfusion. I am using Javascript to concatenate user input from one text box and append it to another when a button is clicked. Both form fields have names that are iterative and variable - eg: medinput_1, medinput_2, medinput_3, medlist_1, medlist_2, medlist_3 etc. I cannot figure out how to resolve the passed argument (cr) of the row number into the form field name. In the code below, the variable newtext works the way I want it to and gives the correct value. But the variable medlist comes up as 'null or not an object' when used in the statement frm.medlist.value += '*' + newtext + '\n' ;
Also, if there is a better way than using the evil eval function what is it?. Thank you in advance.
function addtext(cr) {
var frm = document.EditForm;
var newtext = eval('frm.medinput_' + cr + '.value');
var medlist = eval('frm.medlist_' + cr);
frm.medlist.value += '*' + newtext + '\n' ;
}