javascript - How to replace a letter with another letter in a textbox -


say want target specific letter in textbox region , replace letter using either jquery or javascript, how , still able target letter afterwards, , again, , again etc.? letter change , changed inputed either textbox or dropdown (whichever easier)

p.s tried jquery's replace function , didn't work (i didn't use correctly though :)

$( "button" ).click( function() {     $( "changed" ).replacewith( $( "new" )        ); }); 

$("button").click(function() {     var old = $("#changed").val();     var replacement = $("#new").val();     var regexp = new regexp(old, 'g');     $("#input").val(function(i, current) {         return current.replace(regexp, replacement);     }); }); 
  1. you need use # before ids select them.
  2. you need values of inputs using .val().
  3. jquery's .replacewith replacing entire dom elements, not changing value of input.
  4. you use .val() change value of input. when argument function, function gets called current value parameter, , return value put in place.
  5. the javascript method .replace() used perform replacements in strings. multiple replacements, need use regexp g flag.

demo


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -