Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function serialize(form) {
- if (!(form instanceof HTMLFormElement)) {
- return;
- }
- var q = [];
- function push(k, v) {
- q.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
- }
- for (var i = 0, el, j; i < form.elements.length; ++i) {
- el = form.elements[i];
- if (!el.name || (el.tagName == 'INPUT' && (el.type == 'file' || ((el.type == 'radio' || el.type == 'checkbox') && !el.checked)))) {
- continue;
- }
- if (el.tagName == 'SELECT') {
- if (el.multiple) {
- for (j = 0; j < el.options.length; ++j) {
- if (el.options[j].selected) {
- push(el.name, el.options[j].value);
- }
- }
- }
- else {
- push(el.name, el.options[el.selectedIndex].value);
- }
- }
- else {
- push(el.name, el.value);
- }
- }
- return q.join('&');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement