• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting string integer value to real integer value for looping

 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK this should be simple but I am scratching my head on it. I have a string value of an number within an html page(works fine). I then want to convert it to an integer so I can iterate through a fixed number of fields(totalSize var).
Code snippit below. I get this NaN value (putting totalSize inside of an alert())when doing parseInt. I want to be able to iterate through "totalSize". How do I do that once I have the correct string representation of my integer? Is there something I need to call on the Nan value to do it or?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parseInt() should work fine, even if there's trailing spaces in the string. What exactly does the string contain?
 
steve kelly
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:parseInt() should work fine, even if there's trailing spaces in the string. What exactly does the string contain?

Never mind. Gah, I was passing in wrong value. I need coffee<grin>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using parseInt, you really should use a radix.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
steve kelly wrote:I need coffee<grin>

Ah yes, uncaffeinated coding -- it's a killer!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic