WonderBugger WonderBugger - 1 month ago 10
jQuery Question

How to replace part of an input value in jquery?

I've been trying to figure out a way to replace part of a string in an input value, but haven't been able to get it working.

the input field looks like this:

<input type="text" value="20,54,26,99" name="ids" />


I've tried:

$('input[name=ids]').val().replace("54,","");


and

var replit = $('input[name=ids]').val();
replit.replace("54,","");
$('input[name=ids]').val(replit);


but neither worked?

Answer
$('input[name=ids]').val(function(index, value) {
   return value.replace('54,', '');
});