-2

I am using jquery 1.10.2. I am trying to get the following piece of code to work:

$("[id*='value_']").val($(this).val());

I know as written the code will just set the value to whatever is currently in the tag. But this is as far as I can go until I get rid of the error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3; Tablet PC 2.0)
Timestamp: Mon, 10 Feb 2014 15:51:01 UTC


Message: Unable to get value of the property 'toLowerCase': object is null or undefined
Line: 5
Char: 6176
Code: 0
URI: https://ox-kkent11.fncinc.com/wssp/js_files/jquery-1.10.2.min.js

For instance:

$("[id*='value_']").val(2);

successfully writes a '2' in all fields that have an id that begins with "value_".

I intend to take the value of the field and convert it to currency. But get the error before I can even try that.

Any pointers. Plus if anyone knows of a more efficient way to turn all numbers (int and float) to currency with a '$', please tell me.

TaZz
  • 652
  • 7
  • 20
Mildfire
  • 323
  • 1
  • 5
  • 15

1 Answers1

1

If you want to add a "$" to the value of some elements, it would look like this:

$("[id*='value_']").each(function() {
  $(this).val( "$" + $(this).val() );
});
Pointy
  • 405,095
  • 59
  • 585
  • 614
  • i just thought about this. I will let you know if it works. THank you – Mildfire Feb 10 '14 at 16:11
  • this is what i ended up doing if anyone was curious: $("[id*='value_']").each(function () { if ($(this).val().indexOf(".") < 0) { $(this).val($(this).val() + '.00'); } if ($(this).val().indexOf("$") < 0) { $(this).val("$" + $(this).val()); } }); – Mildfire Feb 10 '14 at 21:17