{"id":268,"date":"2012-02-10T12:51:09","date_gmt":"2012-02-10T12:51:09","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=268"},"modified":"2022-02-17T07:14:47","modified_gmt":"2022-02-17T07:14:47","slug":"adding-a-variable-to-a-form","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/forms-javascript\/adding-a-variable-to-a-form","title":{"rendered":"Adding a variable to a form"},"content":{"rendered":"<h5>Create the form<\/h5>\n<pre><code>\r\n&lt;form id=\"my_form_name\" name=\"my_form_name\" method=\"post\" action=\"http:\/\/www.mydomain.com\/destination_page.php\"&gt;\r\n   &lt;input type=\"hidden\" name=\"form_parameter1\" id=\"form_parameter1\" value=\"\" \/&gt;\r\n   &lt;!-- etc... --&gt;\r\n&lt;\/form&gt;\r\n<\/code><\/pre>\n<h5>Create the variable<\/h5>\n<pre><code>\r\n&lt;script type=\"text\/javascript\"&gt;\r\nvar parameter1 = 'TEST';\r\n&lt;\/script&gt;\r\n<\/code><\/pre>\n<h5>To load the form field with the varaible<\/h5>\n<pre><code>\r\ndocument.getElementById('form_parameter1').value=parameter1;\r\n\/\/If you want to auto submit the form\r\ndocument.forms[\"my_form_name\"].submit();\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create the form &lt;form id=&#8221;my_form_name&#8221; name=&#8221;my_form_name&#8221; method=&#8221;post&#8221; action=&#8221;http:\/\/www.mydomain.com\/destination_page.php&#8221;&gt; &lt;input type=&#8221;hidden&#8221; name=&#8221;form_parameter1&#8243; id=&#8221;form_parameter1&#8243; value=&#8221;&#8221; \/&gt; &lt;!&#8211; etc&#8230; &#8211;&gt; &lt;\/form&gt; Create the variable &lt;script type=&#8221;text\/javascript&#8221;&gt; var parameter1 = &#8216;TEST&#8217;; &lt;\/script&gt; To load the form field with the varaible document.getElementById(&#8216;form_parameter1&#8217;).value=parameter1; \/\/If you want to auto submit the form document.forms[&#8220;my_form_name&#8221;].submit();<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-forms-javascript"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/268","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=268"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":1461,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/268\/revisions\/1461"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}