Add data when form is submitted
Sometimes we want to add extra data to our form and submit them to the server.
We can do this like :
1 var form = document.querySelector('form'); 2 form.onsubmit = function(){ 3 var input = document.createElement('input'); 4 input.setAttribute('type','hidden'); 5 input.setAttribute('name', elementName); 6 input.setAttribute('value',elementValue); 7 form.appendChild(input); 8 }