JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="m_ci" />
<input type="text" id="rp_ci" />
<input type="text" id="m_prueba1" />
<input type="text" id="rp_prueba1" />
<input type="text" id="m_prueba2" />
<input type="text" id="rp_prueba2" />
<input type="button" onclick="copy()" value="Copiar" />
JavaScript
function copyData(from,to)
{
//var fields = ['nombre','apellido','profesion','ocupacion','direc_habi','telf_hab','direc_trab','telf_trab'];
var fields = ['prueba1','prueba2'];
var length = fields.length;
for(var i = 0;i<length;i++)
{
document.getElementById(to+fields[i]).value = document.getElementById(from+fields[i]).value;
}
}
function copy()
{
if(document.getElementById("m_ci").value==document.getElementById("rp_ci").value)
{
copyData('m_','rp_');
}
}