{"id":2821,"date":"2020-05-20T13:51:58","date_gmt":"2020-05-20T12:51:58","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=2821"},"modified":"2024-02-28T11:58:15","modified_gmt":"2024-02-28T11:58:15","slug":"auto-submit-a-form","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/forms-javascript\/auto-submit-a-form","title":{"rendered":"Auto Submit A Form"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Very simple method<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;select name=\"my_playlists\" id=\"my_playlists\" onchange=\"this.form.submit()\"><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Auto submit from javascript<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form id=\"my_form\" action=\"\/my_url\" method=\"POST\"&gt;\n  &lt;input type=\"text\" name=\"one_time_code\" \/&gt;\n  &lt;input type=\"submit\" id=\"SubmitCodeButton\" value=\"Submit\" \/&gt;\n&lt;\/form&gt;\n\n  &lt;script type=\"text\/javascript\" &gt;\n\n    \/\/----- AUTO SUBMIT THE FORM - VALUE PASTED -----\n    function submit_my_form() {\n      document.getElementById('my_form').submit();\n    }\n    \n  &lt;\/script&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Auto submit from paste or key up<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form id=\"submit_received_code_form\" action=\"\/my_url\" onsubmit=\"return DisablePageUntilReloaded()\" method=\"POST\"&gt;\n  &lt;input type=\"text\" id=\"one_time_code\" name=\"one_time_code\" onpaste=\"check_field_value_entered()\" minlength=\"4\" maxlength=\"4\" \/&gt;\n  &lt;input type=\"submit\" id=\"SubmitCodeButton\" value=\"Submit\" \/&gt;\n&lt;\/form&gt;\n\n\n  &lt;script type=\"text\/javascript\" &gt;\n\n    \/\/----- AUTO SUBMIT THE FORM - VALUE PASTED -----\n    function check_field_value_entered() {\n      \/\/Needs a delay so the pasted value is loaded into the input box\n      setTimeout(function(e) {\n\n        var value = document.getElementById('one_time_code').value;\n        if (value.length == 4) {\n          document.getElementById( 'SubmitCodeButton' ).style.display='none';\n          document.getElementById( 'submit_received_code_form' ).submit();\n        }\n      }, 50);\n    }\n    \n    \/\/----- AUTO SUBMIT THE FORM - KEY UP EVENT -----\n    jQuery(function() {\n      var one_time_code = jQuery('#one_time_code');\n      one_time_code.keyup(function() {\n        if (one_time_code.val().length == 4) {\n          document.getElementById( 'SubmitCodeButton' ).style.display='none';\n          jQuery(this.form).submit();\n        }\n      });\n    });\n    \n  &lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Very simple method Auto submit from javascript Auto submit from paste or key up<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[243,49,62],"tags":[],"class_list":["post-2821","post","type-post","status-publish","format-standard","hentry","category-auto-submit","category-forms-javascript","category-text"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/2821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=2821"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/2821\/revisions"}],"predecessor-version":[{"id":4295,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/2821\/revisions\/4295"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=2821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=2821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=2821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}