Jump to content

JSNovice10

Members
  • Posts

    3
  • Joined

  • Last visited

JSNovice10's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thank you. Could you possibly give me an example of how that would look?
  2. Thanks for your response. That's part of my question - how and where am I best adding this?
  3. Hello,I am on a steep learning curve, and am trying to add some JavaScript to an existing set of functions which are working well. Any help would be very much appreciated!Essentially we have a set of functions which check a number of values and either display/sum them. We need to add a second span next to all of the existing "days" spans to calculate the days in years (i.e. divide by 365.25).My new sections are named the same as the existing sections, but have "Years" on the end of the id - e.g. valueCurrentDuration becomes valueCurrentDurationYears. When I add studyDuration("underPost","valueUnderPostDurationYears"); into the studyDurationAll function, the value displays correctly. When I try to divide this by 365.25, it fails. I have tried a number of different ways of doing this and have not had any luck. The existing JS is as below:<script type="text/javascript">window.onload = studyDurationAll;function studyDurationAll() { studyDuration("current","valueCurrentDuration"); studyDuration("preDegree","valuePreDegreeDuration"); studyDuration("underPost","valueUnderPostDuration"); studyDuration("doctoral","valueDoctoralDuration"); totalStudyDuration();}function studyDuration(section,display) { if (document.getElementById(section)) { var spanArray = document.getElementById(section).getElementsByTagName("span"); var totalStudyDuration = Number(0); for(i = 0; i < spanArray.length; i++){ totalStudyDuration = totalStudyDuration + Number(spanArray.innerHTML); } if (document.getElementById(display)){ var sectionTotal = document.getElementById(display) sectionTotal.innerHTML = totalStudyDuration; } }}function totalStudyDuration(){ var totalStudyDuration = document.getElementById("valueTotalStudyDuration"); if (document.getElementById("valueCurrentDuration")) { var valueCurrentDuration = document.getElementById("valueCurrentDuration").innerHTML; } else { var valueCurrentDuration = 0 } if (document.getElementById("valuePreDegreeDuration")) { var valuePreDegreeDuration = document.getElementById("valuePreDegreeDuration").innerHTML; } else { var valuePreDegreeDuration = 0 } if (document.getElementById("valueUnderPostDuration")) { var valueUnderPostDuration = document.getElementById("valueUnderPostDuration").innerHTML; } else { var valueUnderPostDuration = 0 } if (document.getElementById("valueDoctoralDuration")) { var valueDoctoralDuration = document.getElementById("valueDoctoralDuration").innerHTML; } else { var valueDoctoralDuration = 0 } totalStudyDuration.innerHTML = Number(valueCurrentDuration) + Number(valuePreDegreeDuration) + Number(valueUnderPostDuration) + Number(valueDoctoralDuration); var totalPreDegreeDuration = document.getElementById("valueTotalPreDegreeDuration"); totalPreDegreeDuration.innerHTML = valuePreDegreeDuration;}</script>I would be so grateful for any help.Thank you! C
×
×
  • Create New...