Skip to content

Instantly share code, notes, and snippets.

@homer6
Created November 15, 2011 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homer6/1367465 to your computer and use it in GitHub Desktop.
Save homer6/1367465 to your computer and use it in GitHub Desktop.
Answer to a stackoverflow question
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script>
$(function(){
$( '.submit_button' ).click(function(){
var form_values = {};
$( this ).closest( 'tr' ).find( 'input, select' ).each(function(){
form_values[ $(this).attr('name') ] = $(this).val();
});
if( form_values.undefined ){
delete form_values.undefined;
}
$.post( "/test.php",
form_values,
function(data){
//success
alert( data );
},
"json"
);
});
});
</script>
</head>
<body>
<table>
<tr>
<td><input type="text" name="value1" value="text1"/></td>
<td><select name="option"><option value="1">1</option><option value="2">2</option></select></td>
<td><input type="button" class="submit_button" value="Send" /></td>
</tr>
<tr>
<td><input type="text" name="value2" value="text2"/></td>
<td><select name="option"><option value="3">3</option><option value="4">4</option></select></td>
<td><input type="button" class="submit_button" value="Send" /></td>
</tr>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment