{"id":391,"date":"2024-04-16T23:57:22","date_gmt":"2024-04-16T23:57:22","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=391"},"modified":"2024-04-19T03:29:58","modified_gmt":"2024-04-19T03:29:58","slug":"form-validation2","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/04\/16\/form-validation2\/","title":{"rendered":"\ud3fc \uc720\ud6a8\uc131 \ud655\uc778\ud558\uae30(Form Validation)(2)"},"content":{"rendered":"\n<p>\uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ubd80\ubd84(JavaScript part) <br>\uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\uc758 document.getElementById(&#8220;[\ubcc0\uc218 variable]&#8221;.value)\uc5d0\uc11c \ubcc0\uc218\uc5d0 \ud574\ub2f9\ud558\ub294 \ubd80\ubd84\uc740 HTML\uc5d0\uc11c id=&#8221;\ubcc0\uc218 variable&#8221; \ubd80\ubd84\uc774\ub2e4.<br>In JavaScript&#8217;s document.getElementById (&#8220;[variable]&#8221;.value), the part that corresponds to a variable is the id=&#8221;variable&#8221; part of HTML.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>                const frmName     = document.getElementById(\"<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">name<\/mark>\").value;\n                &lt;input type=\"name\" class=\"form-control\" <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">id=\"name\"<\/mark> placeholder=\"\ub2f9\uc2e0\uc758 \uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Enter Your Name)\" name=\"name\"&gt;\n\n                const frmPwd      = document.getElementById(\"<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">pwd<\/mark>\").value;\n                &lt;input type=\"password\" class=\"form-control\" <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-green-color\">id=\"pwd\"<\/mark> placeholder=\"Enter password\" name=\"pswd\"&gt;<\/code><\/pre>\n\n\n\n<p>\ubc84\ud2bc \ud074\ub9ad\ud588\uc744 \ub54c \ud3fc &#8220;frumSubmit()&#8221;\uc774 \uc2e4\ud589\ub41c\ub2e4.<br>When the button is clicked, the form &#8220;frumSubmit()&#8221; runs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>                &lt;button type=\"button\" onClick=\"frmSubmit();\" class=\"btn btn-primary\"&gt;Submit&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<p><br>\uc804\uccb4\ucf54\ub4dc(full code)<br>-\uc544\ub798\uc758 \ub9c1\ud06c\ub97c \ud1b5\ud574\uc11c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4<br>You can test it through the link below.<br><a rel=\"noreferrer noopener\" href=\"https:\/\/freelifemakers.org\/lec\/form3.php\" target=\"_blank\">https:\/\/freelifemakers.org\/lec\/form3.php<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n    &lt;head&gt;\n      &lt;title&gt;Bootstrap 5 Example&lt;\/title&gt;\n      &lt;meta charset=\"utf-8\"&gt;\n      &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"&gt;\n      &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\"&gt;\n      &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.2.3\/dist\/js\/bootstrap.bundle.min.js\"&gt;&lt;\/script&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;form name=\"frm\" action=\".\/form_action2.php\" method=\"get\"&gt;\n        &lt;div class=\"mb-3 mt-3\"&gt;\n            &lt;label for=\"name\" class=\"form-label\"&gt;\uc774\ub984(Name):&lt;\/label&gt;\n            &lt;input type=\"name\" class=\"form-control\" id=\"name\" placeholder=\"\ub2f9\uc2e0\uc758 \uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Enter Your Name)\" name=\"name\"&gt;\n            &lt;div id=\"errorName\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"mb-3\"&gt;\n            &lt;label for=\"pwd\" class=\"form-label\"&gt;Password:&lt;\/label&gt;\n            &lt;input type=\"password\" class=\"form-control\" id=\"pwd\" placeholder=\"Enter password\" name=\"pswd\"&gt;\n            &lt;div id=\"errorPwd\"&gt;&lt;\/div&gt;\n        &lt;\/div&gt;\n            &lt;div class=\"form-check mb-3\"&gt;\n            &lt;label class=\"form-check-label\"&gt;\n            &lt;input class=\"form-check-input\" type=\"checkbox\" name=\"remember\"&gt; Remember me\n            &lt;\/label&gt;\n        &lt;\/div&gt;\n            &lt;button type=\"button\" onClick=\"frmSubmit();\" class=\"btn btn-primary\"&gt;Submit&lt;\/button&gt;\n        &lt;\/form&gt;\n        &lt;script&gt;\n            function frmSubmit(){\n                const frmName     = document.getElementById(\"name\").value;\n                const frmPwd      = document.getElementById(\"pwd\").value;\n\n                errorName.innerHTML = \"\";\n                errorPwd.innerHTML  = \"\";\n\n                if(frmName == \"\"){\n                    errorName.innerHTML = \"&lt;p&gt;\uc774\ub984\uc744 \uc785\ub825\ud558\uc138\uc694(Please Enter Your Name)&lt;\/p&gt;\";\n                } else if(frmPwd == \"\"){\n                    errorPwd.innerHTML = \"&lt;p&gt;\ud328\uc2a4\uc6cc\ub4dc\ub97c \uc785\ub825\ud558\uc138\uc694(Please Enter Your Password)&lt;\/p&gt;\";\n                }else{\n                    frm.submit();\n                }\n            }\n        &lt;\/script&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;    <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8 \ubd80\ubd84(JavaScript part) \uc790\ubc14\uc2a4\ud06c\ub9bd\ud2b8\uc758 document.getElementById(&#8220;[\ubcc0\uc218 variable]&#8221;.value)\uc5d0\uc11c \ubcc0\uc218\uc5d0 \ud574\ub2f9\ud558\ub294 \ubd80\ubd84\uc740 HTML\uc5d0\uc11c id=&#8221;\ubcc0\uc218 variable&#8221; \ubd80\ubd84\uc774\ub2e4.In JavaScript&#8217;s document.getElementById (&#8220;[variable]&#8221;.value), the part that corresponds to a variable is the id=&#8221;variable&#8221; part of HTML. \ubc84\ud2bc \ud074\ub9ad\ud588\uc744 \ub54c \ud3fc &#8220;frumSubmit()&#8221;\uc774 \uc2e4\ud589\ub41c\ub2e4.When the button is clicked, the form &#8220;frumSubmit()&#8221; runs. \uc804\uccb4\ucf54\ub4dc(full code)-\uc544\ub798\uc758 \ub9c1\ud06c\ub97c \ud1b5\ud574\uc11c \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4You can test it through [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-391","post","type-post","status-publish","format-standard","hentry","category-php","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=391"}],"version-history":[{"count":13,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/391\/revisions\/440"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}