Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace part of an input value in jQuery?

Tags:

jquery

replace

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?

like image 408
WonderBugger Avatar asked Dec 22 '10 02:12

WonderBugger


1 Answers

I used this method, however I also included a line of code that replaces part of a string.

var matval = document.getElementById("MaterialNumber").value;

var matNum = matval.replace("P", "");

document.getElementById("MaterialNumber").value = "";

document.getElementById("MaterialNumber").value = matNum;

Generally I would not have cleared out the field before putting in the new string, but it did not work like that in this case, This might have been caused by the input method being a barcode scanner and set into a function based on a keypress of that said barcode scanner.

like image 82
Brownbagger11 Avatar answered Oct 26 '22 20:10

Brownbagger11