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     }

 

posted @ 2015-05-16 22:27  青苔1943  阅读(168)  评论(0编辑  收藏  举报