javascript - functionality changes after inserting text to textarea -


my questions arises this topic. i'm stumped , have been trying hours. this fiddle shows text inserted textarea when 1 of options chosen.

by typing words in textarea text of textarea not change when choose option. that's ok. when delete words whole functionality lost somehow.

if helps understand mean , want i'll write small 'testplan' because i'm absolutely stumped:

  1. open the fiddle
  2. type 'a' after 'text' in textarea.
  3. select option 2 ->'texta' stays in textarea
  4. now delete 'texta'
  5. select option1 -> can see textarea stays empty though selected option 1

how can prevent behaviour? added words textarea shall stay time. if thereis no addition, behavior shall not change.

have got idea?

html() wrong way set contents of textarea. use val() instead.

the reason textarea gets initial value text contained between start , end tags. current value stored in value property. changing textarea's child nodes using innerhtml (which jquery's html() method does) works initially, once value property has been changed (either script or user editing textarea content), link between textarea's child nodes , value broken.

here's updated version of jsfiddle using val() instead of html(): http://jsfiddle.net/j4rkt/5/

bottom line: never use html() current value of textarea.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -