Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created January 24, 2012 20:22
Show Gist options
  • Save glynrob/1672339 to your computer and use it in GitHub Desktop.
Save glynrob/1672339 to your computer and use it in GitHub Desktop.
function autosave(last)
{
if (typeof t!="undefined") {clearTimeout(t);} // reset timer
var data = new Object();
var interests = new Object();
var interestscount = 0;
$('#myform input,#myform textarea,#myform select').each(function(index) {
if ($(this).is(':submit')){
// ignore submit buttons
} else {
if ($(this).is(':checkbox')){
if ($(this).attr('checked')){
data[$(this).attr('name')] = $(this).val();
} else {
data[$(this).attr('name')] = '0';
}
} else {
if ($(this).attr('name') == 'interests[]'){ // if input is an array
interests[interestscount] = $(this).val();
interestscount = interestscount + 1;
} else { // if normal input
data[$(this).attr('name')] = $(this).val();
}
}
}
data['interests'] = interests;
});
// AJAX CALL ADDED HERE
}
//-->
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment