How to Hide a form and submit that form using jquery? Is this possible?
4 Answers
Yes, it is possible:
On your HTML page:
<form id="my-form"> </form> <a href="javascript:void(0);" id="submit">Submit</a> Your script:
$(document).ready(function() { $("a#submit").click(function() { $("#my-form").hide(); $("#my-form").submit(); }); }); If your form contains a Submit button and you want the form to be hidden when the Submit button is pressed, instead you can listen to the submit event and handle it like this:
$("#my-form").submit(function() { $(this).hide(); return true; }); Comments
Do you mean a field within a form that already has data inserted, eg. hard-coded in by you, the developer?
If this is the case, just set an id to the input field, with the value hard-coded in. Then set it's display to 'none'. Use your Jquery to interpret the data as normal.
You could also just make a variable in your jquery script, and avoid all this.
Comments
Since you've added the jquery-ajax tag, I guess you want to submit the form through AJAX. In that case you are probably looking for something like this:
$("#your-form-id").submit(function(){ $.ajax({ type: "POST", url: "some.php", data: $(this).serialize(), success: function(){ $("#your-form-id").hide(); } }); return false; });