2

I am trying to do this with jquery globalization plugin but it fails in the browser (client script error, indexOf())

var newquantity = $.global.parseFloat(edititem.find('td.edititem-quantity > input'));

I used to use the jquery calculation plugin like this:

var newdiscount = edititem.find('td.edititem-discount > input').parseNumber();

and it worked but I'm changing to jquery globalization because of some i18n options it has and would like to use just one of those two plugins rather than both of them on the same site.

Why is the first one failing?

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
mare
  • 13,033
  • 24
  • 102
  • 191

1 Answers1

1

I'm guessing that you might want:

var newquantity = $.global.parseFloat(edititem.find('td.edititem-quantity > input').val());

to get the <input> element's value.

edit — updated: perhaps the value is null sometimes:

var newquantity = 
  $.global.parseFloat(edititem.find('td.edititem-quantity > input').val() || '');

Looking at the source code to the globalization "parseFloat()" function, the first thing it does with the first argument (which, indeed, must be a string, not a jQuery object) is call ".indexOf()". If the value passed in is null, then you'll get an immediate error.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • had it before, didn't work. The error is: Line: 179 Error: Object doesn't support property or method 'indexOf' at line 179 if (value.indexOf(culture.numberFormat.currency.symbol) > -1) { inside jquery.global.js.. – mare Apr 19 '11 at 22:50
  • Well perhaps that happens when the value is null. I'll update the answer. It's almost certainly better to get the value, however, than not to get it :-) – Pointy Apr 20 '11 at 12:58
  • in the end it proves I had some more issues in my code that were preventing the parseFloat() to work. Using val() on jquery object works fine. – mare Apr 26 '11 at 21:55