<script>function cmd(id) { $(document).off('submit'); $(document).on('submit', "#" + id + "send", function () { var command = $("input[name=cmd" + id + "]").val(); var dat = "command" + id + "=" + command; $.ajax({ type: "POST", url: "php/serversend.php", data: dat, success: function(data){ document.getElementById(id + "send").reset(); } }); }); return false; } </script>