Hack Forums
[Javascript] Submit button not sending anything - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [Javascript] Submit button not sending anything (/showthread.php?tid=4962576)



Submit button not sending anything - Facebook Inc - Aug 24, 2015

I'm trying to use this custom-built submit button that was made with this website design that I'm using and I don't know how to make the submit button send a POST request with the forms on my page. So far the only thing the button does is make a "Thank you!" show on the webpage. I'm trying to just make a simple POST request submit button.

Here is the code:
Code
//Signup Form.
        (function() {

            // Vars.
                var $form = document.querySelectorAll('#signup-form')[0],
                    $submit = document.querySelectorAll('#signup-form input[type="submit"]')[0],
                    $message;

            // Bail if addEventListener isn't supported.
                if (!('addEventListener' in $form))
                    return;

            // Message.
                $message = document.createElement('span');
                    $message.classList.add('message');
                    $form.appendChild($message);

                $message._show = function(type, text) {

                    $message.innerHTML = text;
                    $message.classList.add(type);
                    $message.classList.add('visible');

                    window.setTimeout(function() {
                        $message._hide();
                    }, 3000);

                };

                $message._hide = function() {
                    $message.classList.remove('visible');
                };

            // Events.
            // Note: If you're *not* using AJAX, get rid of this event listener.
                $form.addEventListener('submit', function(event) {

                    event.stopPropagation();
                    event.preventDefault();

                    // Hide message.
                        $message._hide();

                    // Disable submit.
                        $submit.disabled = true;

                    // Process form.
                    // Note: Doesn't actually do anything yet (other than report back with a "thank you"),
                    // but there's enough here to piece together a working AJAX submission call that does.
                        window.setTimeout(function() {

                            // Reset form.
                                $form.reset();

                            // Enable submit.
                                $submit.disabled = false;

                            // Show message.
                                $message._show('success', 'Thank you!');
                                //$message._show('failure', 'Something went wrong. Please try again.');

                        }, 750);

                });



* - King of Hearts - Aug 25, 2015

Look at this part of the code:

Code
// Process form.
            // Note: Doesn't actually do anything yet (other than report back with a "thank you"),
            // but there's enough here to piece together a working AJAX submission call that does.
            window.setTimeout(function() {

            // Reset form.
            $form.reset();

            // Enable submit.
            $submit.disabled = false;

            // Show message.
            $message._show('success', 'Thank you!');
            //$message._show('failure', 'Something went wrong. Please try again.');

             //ADD AJAX POST HERE

            }, 750);



RE: Submit button not sending anything - SIM-5724601 - Jan 18, 2026

Check out my threads @Mark