This is my code
function updateName(nombreCampo, valor) {
var campo = document.getElementsByName(nombreCampo)[0];
campo.value = valor;
campo.dispatchEvent(new Event('input', { bubbles: true }));
}
function updateId(nombreCampo, valor) {
var campo = document.getElementById(nombreCampo);
campo.value = valor;
campo.dispatchEvent(new Event('input', { bubbles: true }));
}
function updateFormData(data) {
var listContent = data.TablaContenidos.split(", ").join("n");
updateName('dc.title', data.Titulo);
updateName('dc.contributor.author', data.Autor);
updateId('dc_date_issued_year', data.Ano);
updateName('dc.identifier.citation', data.Citacion);
updateName('dc.publisher', data.Publisher);
updateName('dc.language.iso', data.Idioma);
updateName('dc.subject.proposal', data.Palabras);
updateName('dc.subject.ddc', data.ClasificacionDewey);
updateName('dc.description.abstract', data.Resumen);
updateName('dc.description', data.DescripcionRecurso);
updateName('dc.description.tableofcontents', listContent);
updateName('dc.relation.references', data.ReferenciasBibliograficas);
floatingButton.innerHTML = 'Cargados - Reintentar';
console.log('Datos actualizados.');
}
It works very well, but when I send the form the values are empty. The problem is that I only can use Javascript I can’t modify the actual form logic or the html. And I can’t use the form ID for some reasons.
I hope to set the values with Javascript as if I manually put the values in the inputs
2
Answers
I have found the solution
Adding
campo.dispatchEvent(new Event('change', { bubbles: true }))
The value have been set as If I write it manuallyHere is my previous code.
I think it might be helpful for you.
Good luck