{"id":9070,"date":"2021-10-24T20:09:56","date_gmt":"2021-10-24T17:09:56","guid":{"rendered":"https:\/\/elzero.org\/?p=9070"},"modified":"2022-09-28T18:18:31","modified_gmt":"2022-09-28T15:18:31","slug":"tutorials-count-input-characters-and-fill-borders","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-count-input-characters-and-fill-borders\/","title":{"rendered":"Count Input Characters And Fill Borders"},"content":{"rendered":"<h3>\u0627\u0644 Code<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-html\">\r\n<form action=\"\">\r\n  <div>\r\n    <input type=\"text\" placeholder=\"Your Username\" maxlength=\"20\" \/>\r\n    <span class=\"progress\"><\/span>\r\n    <span class=\"count\"><\/span>\r\n  <\/div>\r\n<\/form>\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-css\">\r\n* {\r\n  box-sizing: border-box;\r\n}\r\nbody {\r\n  font-family: Arial, Helvetica, sans-serif;\r\n}\r\ndiv {\r\n  width: 300px;\r\n  margin: 20px auto;\r\n}\r\ninput {\r\n  padding: 15px;\r\n  width: 100%;\r\n  border: none;\r\n  border-bottom: 2px solid #d7d7d7;\r\n  background-color: #fbfbfb;\r\n}\r\ninput:focus {\r\n  outline: none;\r\n}\r\n.progress {\r\n  background-color: #2196f3;\r\n  height: 2px;\r\n  width: 0;\r\n  display: block;\r\n  position: relative;\r\n  top: -2px;\r\n  transition: 0.5s;\r\n}\r\n.count {\r\n  display: block;\r\n  text-align: right;\r\n  font-size: 12px;\r\n  padding: 5px;\r\n}\r\n.zero {\r\n  font-weight: bold;\r\n  color: red;\r\n}\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\n\r\nlet count = document.querySelector(\".count\");\r\nlet progress = document.querySelector(\".progress\");\r\nlet input = document.querySelector(\"input\");\r\nlet div = document.querySelector(\"div\");\r\nlet maxLength = input.getAttribute(\"maxlength\");\r\n\r\ncount.innerHTML = maxLength;\r\n\r\ninput.oninput = function () {\r\n  count.innerHTML = maxLength - this.value.length;\r\n  count.innerHTML == 0 ? count.classList.add(\"zero\") : count.classList.remove(\"zero\");\r\n  \/\/ Set The Progress\r\n  progress.style.width = `${(this.value.length * 100) \/ maxLength}%`;\r\n};\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644 Code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[879],"tags":[],"class_list":["post-9070","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=9070"}],"version-history":[{"count":3,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9070\/revisions"}],"predecessor-version":[{"id":10361,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9070\/revisions\/10361"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=9070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=9070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=9070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}