Link to home
Start Free TrialLog in
Avatar of Alex Lord
Alex Lord

asked on

Form submit doesn't reach function, instead refreshes page.

 $('#email-attachment-form').submit(function (e) {
        e.preventDefault();
    
         alert("test");
    });

Open in new window


Just testing if submit is triggering.

how the form is created

   $html .=                        '<form id="email-attachment-form" name="email-attachment-form" class="email-act-form-validation"';
            $html .=                              'style="padding:20px 10%;border-top:1px solid #ccc;"';
            $html .=                              'enctype="multipart/form-data" novalidate>';
            $html .=                           '<div class="input-group cf mb-1">';
            $html .=                               '<input type="text" class="form-control" name="attachment-title"';
            $html .=                                       'id="attachment-title" placeholder="Title" required="">';
            $html .=                               '<div class="invalid-feedback">';
            $html .=                                   'Please provide file title.';
            $html .=                               '</div>';
            $html .=                          '</div>';
            $html .=                           '<div class="input-group cf">';
            $html .=                                '<div class="custom-file mb-5">';
            $html .=                                   '<label class="custom-file-label" for="attachment-file">Choose file...</label>';
            $html .=                                   '<input type="file" class="custom-file-input" name="attachment-file" id="attachment-file" required>';
            $html .=                               '</div>';
            $html .=                           '</div>';
            $html .=                           '<div class="input-group cf">';
            $html .=                              '<input id="email-attachment-submit" type="submit"  class="btn btn-secondary" value="Add Attachment" required>';
            $html .=                          '</div>';

            $html .=                       '</form>';

Open in new window


it is called in with ajax, i pretty much have a function called create modal which goes into php echo out the content of this modal, this case a attachment form.

what is happening tho on submit it isnt reaching the function instead it is refreshing and clearing out all sessions.

any tips on why ?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Open the error console in the developer tools of your browser and turn on the "persist" feature. Do any errors show up when you submit the form?