Skip to content

Instantly share code, notes, and snippets.

@bsmirnov
Created January 30, 2012 19:30
Show Gist options
  • Save bsmirnov/1706169 to your computer and use it in GitHub Desktop.
Save bsmirnov/1706169 to your computer and use it in GitHub Desktop.
Get all form values from page and output as string json object
$(function(){
var txt ="{\n";
$("form :input:not([type=hidden])").each(function(i){
var id = $(this).attr("name");
if($(this).is("select")){
var val = $(this).find("option:selected").text();
}
else {
var val = $(this).val();
}
txt +='"'+id+'"'+" : "+'"'+val+'",\n';
console.log(i);
});
txt +="\n}";
console.log(txt);
});
/*
Then something like to
for( k in form) { $("input[name="+k+"]").val(form[k])};
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment