-1

Using jQuery I've found solutions such as this:

$("#submit").click(function () {
    alert($('form1').serialize());
    $.post("submitForm", $("form1").serialize(), function (result) {
        if (result == "success") {
            alert("Record added!");
        } else {
            alert("Could not add Record!");
        }
    });
});

Here is the Full HTML of the method I had described above, Im trying to find the best way to get the data from the the HTML form and send it to the servlet "submitForm".

<html>
 <head>
<title>myForm</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">

    $("#submit").click(function () {
    alert($('form1').serialize());
    $.post("submitForm", $("wmform_174835").serialize(), function (result) {
        if (result == "success") {
            alert("Record added!");
        } else {
            alert("Could not add Record!");
        }
    });
});

</script>
</head>
<body>
<a href="submitForm">MyForm</a>
<form action="submitForm" method="POST" id="form1">
    <input type="text" value="12" name="ID"/>
    <input type="text" value="NameThatComesFirst" name="FirstName"/>
    <input type="text" value="NameThatComesLast" name="LastName"/>
    <input type=submit id="submit" value="submit"/>
</form>
</body>
</html> 
imsofnbamf
  • 33
  • 1
  • 6

1 Answers1

1

Try this -

   $(document).ready(function(){
     $("#submit").click(function () 
       var data = $('#form1').serialize();
       alert(data);
       $.post("submitForm", data, function (result) {
            if (result == "success") {
              alert("Record added!");
            } else {
                alert("Could not add Record!");
            }
       });
    });
   });
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111