I have the following piece of code (Prototype):
$('table_cell_id')
That cell contains a number. How would I get this number into a JavaScript variable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the cell only contains text something like this should do:
innerHTML returns raw string data of the cell. strip() removes leading and trailing whitespaces and Number(x) casts the trimmed string to a number.
If the cell could be empty you wan’t to check for that, of course. Also, it is good to check whether the variable is NaN (not a number).
Here’s a one-liner that should work: