I am trying to update two input fields in a form when clicking one button. I actually had all the code right when using document.getElementById, but the form that I'm using strips the ID's I set away, so I can't use getbyid. If I know the form field name, how could I change my function to do the same thing? Please note that my form has more than two fields, including a submit button, so I don't want to update those.
This is what I used before (with the ID selector) Html:
<input type="text" name="field-1" id="info1">
<input type="text" name="field" id="info2">
<a href="#" onclick="addTxt(['value1','value2'],'info','2')">Populate</a>
JS:
function addTxt(val, id,no)
{
var id = id;
for(var i=1;i<=no;i++){
document.getElementById(id+i).value = val[i-1];
}
}
Fiddle: http://jsfiddle.net/qwz47phx/3/