jquery http html form post
January 25th, 2010
No comments
Problem Space:
You are submitting a html form, which contains many (hidden) form elements that you do not want (or need) sent to the server for processing.
<script type="text/javascript">
// do when submit is pressed
// don't send the 'hidden' textarea content
// its' un-needed and clutters up the post (and wastes bandwidth)
$('form').submit(function() {
var elements = this.elements;
for (i=0; i < elements.length; i++) {
// if textarea id ends in ".tmpl", exclude from post
if (elements[i].id && elements[i].id.match(/\.tmpl$/)) {
// could change the val,...
//$('textarea[name="'+elements[i].id+'"]').val(' ');
//console.log($('textarea[name="'+elements[i].id+'"]').val());
// better, to remove element from submit
$('textarea[name="'+elements[i].id+'"]').attr('disabled', 'disabled');
}
}
//return false; // if false, doesn't submit, good for testing
});
</script>
