Skip to content

Instantly share code, notes, and snippets.

@kmck
Created February 18, 2014 22:56
Show Gist options
  • Save kmck/9082211 to your computer and use it in GitHub Desktop.
Save kmck/9082211 to your computer and use it in GitHub Desktop.
// Assumes jQuery
function form_submit(attributes, action, method) {
var $form = $('<form>').attr({
method: method ||'post',
action: action || window.location.pathname
});
$.each(attributes, function(name, value) {
$(value.indexOf('\n') < 0 ? '<input>' : '<textarea>').attr('name', name).val(value).appendTo($form);
});
$form.appendTo('body').submit().remove();
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment