Jump to content


Javascript, getElementById()


2 replies to this topic

#1 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 29 August 2007 - 04:06 PM

Hey,

I'm having some issues with Javascript and the getElementById() object.

LINE: 850 -- percentProtein = parseFloat(document.getElementById("percentProteinValue").value) / 100;
LINE: 851 -- percentFat = parseFloat(document.getElementById("percentFatValue").value) / 100;
LINE: 852 -- percentCarbs = parseFloat(document.getElementById("percentCarbsValue").value) / 100;

Internet Explorer 6 and 7 spit out an error on line 851: Object does not support this property or method.
It works in Firefox.

However, the previous line works and they're both referencing the same type of object.

I've also tried going to document.formName.percentProteinValue.value; to no avail.

Any help is appreciated on how I can solve this

Thanks,

Edited by Lang, 29 August 2007 - 04:14 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 29 August 2007 - 11:04 PM

What i always recommend doing because of IE (although i found my reasoning to be slightly incorrect), is to store stuff like that in a variable first.
i.e.
var percentProteinObj = document.getElementById('percentProteinValue');
percentProtein = parseFloat(percentProteinObj.value) / 100;


#3 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 30 August 2007 - 12:29 PM

Thanks for the reply rc ;)

I tried what you suggested and still had the same problem. I decided to stop being logical and just changed the names of the objects and the variables. Everything works fine now :rolleyes:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users