Skip to main content

Forms

12th October, 2022

Updated: 13th October, 2022

    modernizr

    css:

    .hasPlaceholder {
      color: #aaa;
    }

    js:

    $(function () {
      if (!$.support.placeholder) {
        var active = document.activeElement
        $('textarea').each(function (index, element) {
          if ($(this).val().length == 0) {
            $(this).html($(this).attr('id')).addClass('hasPlaceholder')
          }
        })
        $('input, textarea')
          .focus(function () {
            if (
              $(this).attr('placeholder') != '' &&
              $(this).val() == $(this).attr('placeholder')
            ) {
              $(this).val('').removeClass('hasPlaceholder')
            }
          })
          .blur(function () {
            if (
              $(this).attr('placeholder') != '' &&
              ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))
            ) {
              $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder')
              //$(this).css('background', 'red');
            }
          })
        $(':text').blur()
        $(active).focus()
        $('form').submit(function () {
          $(this)
            .find('.hasPlaceholder')
            .each(function () {
              $(this).val('')
            })
        })
      }
    })

    e48f8d1e-a1d3-4eda-b68f-b6f58f75ccab

    Created on: 12th October, 2022

    Last updated: 13th October, 2022

    Tagged With: