Node.js examples for HTML:Form
Builds POST parameters for the form specified
// Builds POST parameters for the form specified function build_form_data(form){ this.form = typeof form == 'string' ? document.forms[form] : form; var parameters = []; for(var i = 0; i < this.form.elements.length; i++){ var element = this.form.elements[i]; //for now i am adding radio,checkbox(not control item),text and hidden //later we can add type = select, type = textarea or checkbox control items if((element.type == 'radio' || element.type == 'checkbox') && element.checked){ parameters.push(element.name + '=' + element.value); }/*www . j a v a2s . c o m*/ if(element.type == 'select-one'){ parameters.push(element.name + '=' + element.options[element.selectedIndex].value); } if(element.type == 'text' || element.type == 'hidden'){ parameters.push(element.name + '=' + element.value); } } parameters = parameters.join('&'); return parameters; }