Ahmad Z. Tibi
Ahmad Z. Tibi

Reputation: 429

get form object from JQuery to Javascript function?

I had written an old javascript file which includes some functions and I want to call some of them within JQuery, so how can I get the form object as in this code check_form(frmAddDominate,'<?php echo $_SESSION[sesLang]; ?>') I put the form name "frmAddDominate" because I failed to get its name as variable, anybody have idea?

And here is the complete code:

<script>
    $(document).ready(function() {
        $("#dominateSubmitForm").click(function() {
            if (check_form(frmAddDominate, '<?php echo $_SESSION[sesLang]; ?>')) {
                var form = $(this).closest("form").attr('id');
                var formURL = $('#' + form).attr("action");
                var formData = $('#' + form).serialize();

                $.ajax({
                    type: 'POST',
                    url: formURL,
                    data: formData,
                    success: function(response) {
                        //$('#' + form).find('.form_result').html(response);
                        $("#txtHint").html(response);
                    }
                });
            }
        });
    });
</script>

Upvotes: 0

Views: 94

Answers (1)

codewisp
codewisp

Reputation: 320

Use $(this).closest('form')[0] to get the form element

Upvotes: 5

Related Questions