Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot call method 'replace' of undefined

$(this).find("input[name=amount]").val($(this).find("input[name=amount]").val().replace('$', ''));

Keep getting this error on my developer tools. I just want to replace the character $ with nothing which is ''

Thoughts?

like image 446
wowzuzz Avatar asked Dec 27 '22 07:12

wowzuzz


1 Answers

Your error just says that there is no element that matches your selector, so element.val() is returning undefined, which has no replace method. Try debugging it and console.log() at each step.

Also, you don't need to search for the element twice. Just store it in a variable:

var $input = $(this).find('input[name="amount"]');
$input.val($input.val().replace('$', ''));
like image 73
Blender Avatar answered Feb 13 '23 22:02

Blender