Title: Javascript error on hidden form elements without ID
Last modified: August 22, 2016

---

# Javascript error on hidden form elements without ID

 *  [EXED internet](https://wordpress.org/support/users/exed-internet/)
 * (@exed-internet)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/javascript-error-on-hidden-form-elements-without-id/)
 * Hi,
 * Tested in Chrome and Firefox, a javascript error is raised when the plugin tries
   to set the placeholder on an element without ID, e.g. input type=”hidden”.
 * I have created a little patch for this.
 *     ```
       --- a/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
       +++ b/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
       @@ -86,6 +86,9 @@ jQuery(document).ready(function($){
                       }
               ?>
               $.each($('.<?php echo $gfap_class; ?> input, .<?php echo $gfap_class; ?> textarea'), function () {
       +               if (!this.id) {
       +                       return;
       +               }
                       var gfapId = this.id;
                       var gfapLabel = $('label[for=' + gfapId + ']');
                       $(gfapLabel).hide();
       ```
   
 * [https://wordpress.org/plugins/gravity-forms-auto-placeholders/](https://wordpress.org/plugins/gravity-forms-auto-placeholders/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [EXED internet](https://wordpress.org/support/users/exed-internet/)
 * (@exed-internet)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/javascript-error-on-hidden-form-elements-without-id/#post-5306727)
 * Hi,
 * I had to change my patch, since hidden inputs are not the only fields without
   a html5 placeholder area.
    [https://html.spec.whatwg.org/multipage/forms.html#the-input-element](https://html.spec.whatwg.org/multipage/forms.html#the-input-element)
 * I’ve tried to find another solution (found some solutions using “‘placeholder’
   in element”) but they didn’t work.
 * So for the new patch:
 *     ```
       --- a/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
       +++ b/gravity-forms-auto-placeholders/gravity-forms-auto-placeholders.php
       @@ -86,6 +86,9 @@ jQuery(document).ready(function($){
                       }
               ?>
               $.each($('.<?php echo $gfap_class; ?> input, .<?php echo $gfap_class; ?> textarea'), function () {
       +               if (type == 'hidden' || type == 'file' || type == 'radio' || type == 'checkbox' || type == 'color' || type == 'date' || type == 'range' || type == 'month' || type == 'week' || type == 'time' || type == 'datetime-local') {
       +                       return;
       +               }
       +               if (!this.id) {
       +                       return;
       +               }
                       var gfapId = this.id;
                       var gfapLabel = $('label[for=' + gfapId + ']');
                       $(gfapLabel).hide();
       ```
   
 *  [melmo](https://wordpress.org/support/users/melmo/)
 * (@melmo)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/javascript-error-on-hidden-form-elements-without-id/#post-5306861)
 * Hi,
 * another quick way to resolve this is to change line 90 from
 * var gfapLabel = $(‘label[for=’ + gfapId + ‘]’);
 * to
 * var gfapLabel = $(‘label[for=”‘ + gfapId + ‘”]’);
 * 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Javascript error on hidden form elements without ID’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gravity-forms-auto-placeholders.svg)
 * [Gravity Forms Auto Placeholders](https://wordpress.org/plugins/gravity-forms-auto-placeholders/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravity-forms-auto-placeholders/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravity-forms-auto-placeholders/)
 * [Active Topics](https://wordpress.org/support/plugin/gravity-forms-auto-placeholders/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravity-forms-auto-placeholders/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravity-forms-auto-placeholders/reviews/)

## Tags

 * [javascript error](https://wordpress.org/support/topic-tag/javascript-error/)

 * 2 replies
 * 2 participants
 * Last reply from: [melmo](https://wordpress.org/support/users/melmo/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/javascript-error-on-hidden-form-elements-without-id/#post-5306861)
 * Status: not resolved