Note that there are some explanatory texts on larger screens.

plurals
  1. POTextarea wont act right on blur
    primarykey
    data
    text
    <p>I am having a problem with my textarea on focus and blur. What its suppose to do is take two variables "textField" and "textDefault". textDefault holds the content that the textarea has when the page is loaded. I added this into a variable because i needed to compare the current contents to the original contents.</p> <p>I take the .html() of the textarea, and if it equals the text in the textDefault, i do $(this).html("") to remove the inner html. Then on blur i do the opposite. I check to see if the textField is equal to "" and if it does, to put textDefault's value back into the textarea with $(this).html(textDefault).</p> <p>The problem im having is that it works fine and dandy with clicking on and off the textarea, but if you enter data into the textarea, then backspace all the way, it doesnt put the original data back into the textarea.</p> <p>Any suggestions? Heres the code:</p> <p>PS: I forgot to mention, that in there i set the height to auto on focus, to make the textarea the height of the content, then i set the height to 190 on blur. Just fyi This is so the textarea isnt 100 feet tall when you may only type 2 words.</p> <pre><code>var textField; var textDefault = "Click the title to add a title for this admin dashboard panel. Click here to add a body. This body can contain html, or regular text.\n\nIt can be used for admin notes mainly, but to communicate with other admins as well.\n\nContact the developer of this website (max@haintmorgan.com) to have this widget actually contain php driven content."; $('.admin-note-body textarea').focus(function(){ textField = $(this).html(); if(textField == textDefault){ $(this).html(""); $(this).css('height', 'auto'); } }).blur(function(){ if($('.admin-note-body textarea').html() == ""){ $('.admin-note-body textarea').html(textDefault); $(this).css('height', '190px'); } }); </code></pre> <p>HTML:</p> <pre><code>&lt;textarea rows="" cols=""&gt;Click the title to add a title for this admin dashboard panel. Click here to add a body. This body can contain html, or regular text. It can be used for admin notes mainly, but to communicate with other admins as well. Contact the developer of this website (max@haintmorgan.com) to have this widget actually contain php driven content.&lt;/textarea&gt; </code></pre> <p>For sake of saving you time,</p> <p>Click the title to add a title for this admin dashboard panel. Click here to add a body. This body can contain html, or regular text.\n\nIt can be used for admin notes mainly, but to communicate with other admins as well.\n\nContact the developer of this website (max@haintmorgan.com) to have this widget actually contain php driven content.</p> <p>This is the contents of textDefault. It does the same content on three lines (notice the \n\n) on the html without \n\n. \n is done twice because there is a line break seperating each mini paragraph..</p> <p>Any help is appreciated!</p> <p>Thanks, David</p> <p>PSS: Note the height to 190px works but the html doesnt. I notice doing console.log on everything that textField and .html() and textDefault all hold hte same value no matter what.</p>
    singulars
    1. This table or related slice is empty.
    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. 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