JQuery Submit Hidden Form

I know this is simple, but I cannot understand it today, and I cannot find the right solution.

I have a series of tabs that populate data. At the end there is a confirmation tab. At this point, they can click the submit button. When this button is pressed, the hidden form is filled with all the relevant data. I would like this form to be submitted, but I cannot figure out how to submit the form using JQUery. I tried to make a trigger on a button, but maybe I'm doing it wrong. Below is a sample code for the taht button. Please note that the values ​​are filled out, I just can not get the form to submit

$('#submitAppointment').click(function() { $("#" + formName + "schedule_id option[value='" + $("input[name='appointmentTime']:checked").val() + "']").attr('selected', 'selected'); $("#" + formName + "apt_date").val($("#confirmDate").text()); $("#" + formName + "first_name").val($("#confirmFirstName").text()); $("#" + formName + "last_name").val($("#confirmLastName").text()); $("#" + formName + "email").val($("#confirmEmail").text()); $("#" + formName + "phone").val($("#confirmPhone").text()); $("#" + formName + "notes").val($("#confirmNotes").text()); $('#appt_form').submit(function() { alert('Handler for .submit() called.'); return false; }); }); 

Any ideas on what I need to do to raise the send function?

+4
source share
3 answers

What about

 $('#appt_form').submit(); 

Do not return false from the handler function if you want the form view to continue. If your intention is to leave the form message without refreshing the page, then you are talking about an ajax operation for which you can use $.post() . (It is not clear that this is what you want to do.)

+5
source

Assuming the form you want to submit is found by the #appt_form selector, just use . submit in a form with no arguments (which is just an alias for .trigger('submit') )

 $('#appt_form').submit(); 
+3
source

I think you should try calling

$('#appt_form').submit()

if appt_form is your form id. This command should submit a form based on jQuery documentation.

Here is jQuery to submit function documentation

+2
source

Source: https://habr.com/ru/post/1336803/


All Articles