Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Submit Hidden Form

I know this is simple but I can't figure it out today and I can't find the right solution.

I have a series of tabs which populate data. At the end is a confirmation tab. At this point they can click a 'submit' button. When this button is pressed a hidden form is populated with all the relevant data. I'd like this form to then be submitted but I can't figure out how to submit the form with JQUery. I've attempted to do a trigger on the button but perhaps I'm doing it wrong. Below is a sample of the code for the button taht gets clicked. Note the values populate, I just can't 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'd need to do to rigger the submit function?

like image 488
CogitoErgoSum Avatar asked Dec 29 '22 02:12

CogitoErgoSum


1 Answers

How about

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

Don't return false from the handler function if you want the form submission to actually proceed. If your intention is to have the form post without the page refreshing, then you're talking about an ajax operation for which you could use $.post(). (It's not clear that that's what you want to do however.)

like image 86
Pointy Avatar answered Jan 05 '23 06:01

Pointy