jquery - Basic javascript questioning -


i'm trying set script dynamically change textarea content.

after googling got :

$(document).ready(function() {      // first text modification works fine     $('textarea#modifyme').val('some useless text');      // catching select change     $('select#changemyvalue').bind('change keyup input',function() {         // alert triggers twice         alert('i know want change text');         // not displaying...         $('textarea#modifyme').val('i not want display');     }); }); 

first value setting good, when comes select change detection gets bit odd. alert triggering twice, , second value setting not functioning.

any appreciated! thanks.


thanks answers i've fixed double trigger, still secon .val('sometext') not triggering.

i'm trying apply textarea displaying wysiwyg editor, can change text on load (first .val('xx') call).

i notice if invert these 2 lines :

// alert triggers once alert('i know want change text'); // not displaying... $('textarea#modifyme').val('i not want display'); 

to :

// not displaying... $('textarea#modifyme').val('i not want display'); // alert not trigger if placed here alert('i know want change text'); 

code seem break @ first line, preventing 'alert' display.

is nature of wysiwyg editor preventing text change after page load?


here short version of html code :

<select name="" id="selectme">     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option> </select> <textarea class="textarea callhtml5" name="changeme" id="changeme"></textarea>  <!-- bootstrap wysihtml5 --> <script src="path wysihtml5 bootstrap"></script>  <script>     $(".callhtml5").wysihtml5(); </script>  <script> $(document).ready(function() {      $('textarea#changeme').val('initial text setup');     $('select#selectme').bind('change keyup',function() {         alert('test');         $('textarea#changeme').val('final text setup');     }); }); <script> 

solved problem using :

$('.wysihtml5-sandbox').contents().find('body').html("i got modified"); 

instead of method :

$('textarea#changeme').val('final text setup'); 

it's because of keyup , input. if bind both events callback executes 2 times.

to on come use these 2 bind input. can omit keyup.

one thing mention input event can't captured. mean won't let capture event.


just noticed element <select> element better use change keyup. should avoid using input event not putting text values in changing mouse or keys.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -