Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This doesn't seem to be the best way to tackle this problem. I saw a solution like the following on a blog before. You add the placeholder attribute to the inputs, so they will work on modern browsers, and you add jQuery to inputs with placeholder attributes, like <code>[placeholder]</code>:</p> <pre><code>$('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function() { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur(); $('[placeholder]').parents('form').submit(function() { $(this).find('[placeholder]').each(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }) }); </code></pre> <p>I can't find the blog right now, which is a shame, because this code, I believe, is completely copied from that site and works great, cross-browser.</p> <p><strong>How this works, and why this is a better approach:</strong></p> <p>Instead of putting handlers on every input and textarea element, you can easily filter exactly which ones should have handlers on them: those that have a placeholder attribute.</p> <p>A <code>.submit()</code> handler will keep the default text from being posted as values.</p> <p>Maybe I should speak on what I feel are problems with your code:</p> <p>You're using an each function to call multiple focus handlers, which are quite similar. You probably don't need the each function. You could just use $('input, textarea').focus() because that will add a handler to each input. Then, you could check if <code>$.inArray($(this).val(),formId)</code>. Docs for <a href="http://api.jquery.com/jQuery.inArray/" rel="nofollow">inArray()</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload