• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

jQuery custom wrapper method only works half the time

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm writing a jquery wrapper method which takes a figure eg 1234567.89 from a input box and replaces it with a formatted currency string eg £1,234,567.89 and vica versa.

It SHOULD be working...lol. But isn't.

Basically the way the method works is that it takes whatever is in the input box and reduces it to just numbers a decimal point (.) and two more numbers after the decimal place. This is asigned to the 'result' variable.

Then if the 'direction' option has 'toCurrency', then the necessary commas and currency symbols are added.

The method works fine of the 'toCurrency' option is chosen, but not if it is left out. This is very strange because I have used alerts to check the value of the result variable before the 'if' and I have the correct value. If the 'toCurrency' option is not chosen, it should just miss the 'if' and use the result value which I have just checked on. But it doesn't. I have put an alert at the end of the if statement and it prints out the correct answer if the 'toCurrency' option is chosen, but prints nothing if it is not. Strange. I wonder if anyone can see my mistake? Here is my code:



Many thanks

Joe
 
Joe Lemmer
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got this working now, but I'm not exactly sure why. Basically, when I wanted to convert to a currency with commas etc, I was using a command such as:



whereas I thought it would be fine when I wanted to convert back to a float just to use a command such as:



which doesn't have any options, but in fact it seems to need some sort of options so the following works:



I need to read up about putting in default values. I know I've seen something in the jQuery in action book.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Lemmer wrote:I need to read up about putting in default values. I know I've seen something in the jQuery in action book.

Chapter 7.
 
Joe Lemmer
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear :-)
 
catch it before it slithers away! Oh wait, it's a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic