0

How to Hide a form and submit that form using jquery? Is this possible?

0

4 Answers 4

1

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; }); 
Sign up to request clarification or add additional context in comments.

Comments

0

What are you trying to do? Some scam?

You can place the form in a hidden div and using $(document).ready event, you can autosubmit the form.

Comments

0

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

0

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; }); 

3 Comments

I believe the order was the opposite: first hide, then submit. And I believe it should be hidden from the beginning, but I may be wrong in this case.
I think that code will submit the form twice, once with ajax and once without ajax.
@Tadeck It appears as if you were right, looking at the accepted answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.