سؤال

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.

هل كانت مفيدة؟

المحلول

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() );
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top