{"id":427,"date":"2015-01-23T09:54:24","date_gmt":"2015-01-23T09:54:24","guid":{"rendered":"http:\/\/shabeebk.com\/blog\/?p=427"},"modified":"2015-01-23T09:54:24","modified_gmt":"2015-01-23T09:54:24","slug":"clear-form-using-javascript","status":"publish","type":"post","link":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/","title":{"rendered":"Clear your form using Javascript"},"content":{"rendered":"<p>If you need to clear all the input fields irrespective of type in a form, try the below code.\u00a0 The below code works even if your fields contains place holders.<\/p>\n<pre class=\"lang:default decode:true \" title=\"Clear all Input Types in a Form\">    $.fn.clearForm = function() {\r\n      return this.each(function() {\r\n        $(':input', this).each(function() {\r\n          var type = this.type, tag = this.tagName.toLowerCase();\r\n          if (type == 'text' || type == 'password' || tag == 'textarea')\r\n            this.value = '';\r\n          else if (type == 'checkbox' || type == 'radio')\r\n            this.checked = false;\r\n          else if (tag == 'select')\r\n            this.selectedIndex = -1;\r\n        });\r\n      });\r\n    };<\/pre>\n<p>&nbsp;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"427\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;3,717&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you need to clear all the input fields irrespective of type in a form, try the below code.\u00a0 The below code works even if your fields contains place holders. $.fn.clearForm = function() { return this.each(function() { $(&#8216;:input&#8217;, this).each(function() { var type = this.type, tag = this.tagName.toLowerCase(); if (type == &#8216;text&#8217; || type == &#8216;password&#8217; [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"427\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;3,717&nbsp;total views, &nbsp;1&nbsp;views today<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[4,14],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.4.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Clear your form using jquery \/ javascript<\/title>\n<meta name=\"description\" content=\"If you need to clear all the input fields irrespective of type in a form using javascript.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Clear your form using jquery \/ javascript\" \/>\n<meta property=\"og:description\" content=\"If you need to clear all the input fields irrespective of type in a form using javascript.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"shabeeb Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-23T09:54:24+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hari Rajagopal\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\",\"url\":\"http:\/\/shabeebk.com\/blog\/\",\"name\":\"shabeeb Blog\",\"description\":\"A developer blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/shabeebk.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/#webpage\",\"url\":\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/\",\"name\":\"Clear your form using jquery \/ javascript\",\"isPartOf\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#website\"},\"datePublished\":\"2015-01-23T09:54:24+00:00\",\"dateModified\":\"2015-01-23T09:54:24+00:00\",\"author\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/0c0176d75f3bd69f708911119beca283\"},\"description\":\"If you need to clear all the input fields irrespective of type in a form using javascript.\",\"breadcrumb\":{\"@id\":\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/shabeebk.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Clear your form using Javascript\"}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/0c0176d75f3bd69f708911119beca283\",\"name\":\"Hari Rajagopal\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/shabeebk.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/d27d56483e3cf970c777221418de70a8?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/d27d56483e3cf970c777221418de70a8?s=96&d=mm&r=g\",\"caption\":\"Hari Rajagopal\"},\"url\":\"http:\/\/shabeebk.com\/blog\/author\/harirajagopal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Clear your form using jquery \/ javascript","description":"If you need to clear all the input fields irrespective of type in a form using javascript.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Clear your form using jquery \/ javascript","og_description":"If you need to clear all the input fields irrespective of type in a form using javascript.","og_url":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/","og_site_name":"shabeeb Blog","article_published_time":"2015-01-23T09:54:24+00:00","twitter_misc":{"Written by":"Hari Rajagopal"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"http:\/\/shabeebk.com\/blog\/#website","url":"http:\/\/shabeebk.com\/blog\/","name":"shabeeb Blog","description":"A developer blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/shabeebk.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/#webpage","url":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/","name":"Clear your form using jquery \/ javascript","isPartOf":{"@id":"http:\/\/shabeebk.com\/blog\/#website"},"datePublished":"2015-01-23T09:54:24+00:00","dateModified":"2015-01-23T09:54:24+00:00","author":{"@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/0c0176d75f3bd69f708911119beca283"},"description":"If you need to clear all the input fields irrespective of type in a form using javascript.","breadcrumb":{"@id":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/shabeebk.com\/blog\/clear-form-using-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/shabeebk.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Clear your form using Javascript"}]},{"@type":"Person","@id":"http:\/\/shabeebk.com\/blog\/#\/schema\/person\/0c0176d75f3bd69f708911119beca283","name":"Hari Rajagopal","image":{"@type":"ImageObject","@id":"http:\/\/shabeebk.com\/blog\/#personlogo","inLanguage":"en-US","url":"http:\/\/1.gravatar.com\/avatar\/d27d56483e3cf970c777221418de70a8?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/d27d56483e3cf970c777221418de70a8?s=96&d=mm&r=g","caption":"Hari Rajagopal"},"url":"http:\/\/shabeebk.com\/blog\/author\/harirajagopal\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/427"}],"collection":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":1,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":428,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions\/428"}],"wp:attachment":[{"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shabeebk.com\/blog\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}