Solved

Basic Javascript Help

Posted on 2014-11-03
6
137 Views
Last Modified: 2014-11-03
I have some basic HTML and assigned an ID

<div id="somecontent">48793748</div>

I want to find the number value of the div

so I know its something like

document.getElementById("somecontent")

I need to assign a variable and end up with the value being a number

If I do a document.getElementById("somecontent").innerHTML
I get "48793748" but its a string not a number.  How do I convert or change the getElementById so that it returns a number?
0
Comment
Question by:Baub Eis
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40420040
parseInt(document.getElementById("somecontent").innerHTML)
0
 

Author Comment

by:Baub Eis
ID: 40420061
that drops info past the decimal point.

39.000329 returns 39

How can I get it to return the value of 39.000329 from the element?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40420062
parseFloat(document.getElementById("somecontent").innerHTML)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Baub Eis
ID: 40420063
parseFloat got it
0
 

Author Comment

by:Baub Eis
ID: 40420066
so can I assign a variable with it?

var myvar = parseFloat(document.getElementById("somecontent.innerHTML)

?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40420117
Yep
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sums of coloumns in html/java 15 68
Accessing data in JSON response.d multiple objects 2 60
Need to click button twice to get results 2 34
Split in Javascript 5 31
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now