Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number
Javascript; converting string to number Javascript; converting string to number
Javascript; converting string to number
Go Back  Xtreme Visual Basic Talk > > > Javascript; converting string to number


Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2012, 11:29 PM
PeetSoft's Avatar
PeetSoft PeetSoft is offline
Centurion
 
Join Date: Jun 2003
Location: HHW - the Netherlands
Posts: 184
Default Javascript; converting string to number


I want to change the forecolor of my temperature display according to outside temp.

The original value of the temp ia a string, e.g "15,4" (checked with typeOf)
I used the replace function to change the comma to a decimal "15.4"

Whatever I try, I can't get the string to be a number

If I use

document.getElementById("outtemp").value; - it gives me Undefined
document.getElementById("outtemp").innerHTML; - it gives me string value

parseInt, parseFloat and multiplying by 1 keeps on NaN-ning me.

How to get an integer value out of string value?

t.i.a.
__________________
-----------------------------------------------------
If debugging is the art of removing bugs, then
programming must be the art of inserting them.
I do comply with Flyguy's signature (If he still had one)
Reply With Quote
  #2  
Old 07-25-2012, 09:22 PM
MikeJ's Avatar
MikeJJavascript; converting string to number MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Have you tried explicitly converting the element to a string before trying a parseInt?
Code:
var myInt = parseInt(document.getElementById('outtemp').innerHTML.toString());
If that doesn't work, what browser are you using?
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number Javascript; converting string to number
Javascript; converting string to number
Javascript; converting string to number
 
Javascript; converting string to number
Javascript; converting string to number
 
-->