0

i serch about 1 month to find a script that names biorhythms and i found a script! my problem is that the script works in internet explorer but not in firefox and i do not know why!
i will sent the code...can any one help me and say to me what i have to do?thanks a lot and sorry for my english...i am from greece
code:

<SCRIPT LANGUAGE="JavaScript">



<!-- Begin
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");


function countup() {


 yr = (yea.value) ;
 m = (mon.value) ;
 d = (day.value) ;


var today=new Date();
var todayy=today.getYear();

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))
todayy="19" + todayy;
if (navigator.appName == "Netscape")
todayy=1900 + todayy;

var todaym=today.getMonth();
var todayd=today.getDate();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy;
var paststring=montharray[m-1]+" "+d+", "+yr;
var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1);

birthm.value=difference;
ph.value=Math.round(100*Math.sin((2*Math.PI/23)*difference));
int.value=Math.round(100*Math.sin((2*Math.PI/33)*difference));
em.value=Math.round(100*Math.sin((2*Math.PI/28)*difference));

av.value=Math.round((parseInt(ph.value) + parseInt(int.value) + parseInt(em.value))/3);


}
//  End -->
</script>
4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Airshow
0
<SCRIPT LANGUAGE="JavaScript">

This is not supposed to be only 'javascript'. It should be...<SCRIPT LANGUAGE="text/JavaScript">

yr = (yea.value) ;
 m = (mon.value) ;
 d = (day.value) ;

Where are yea, mon, and day variable? You have not declared them earlier, so they are unknown to browser.

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))
todayy="19" + todayy;
if (navigator.appName == "Netscape")
todayy=1900 + todayy;

Where are other browsers? Firefox is not 'Netscape'

From what I see, you showed only one part of the script. I believe that the code is relied on another script... Also, the script seems to be outdated...

0

This is not supposed to be only 'javascript'. It should be...<SCRIPT LANGUAGE="text/JavaScript">

Shouldn't this be:

<script type="text/javascript">

Agree on the rest, didn't even notice.

1

H,

The code can be simplified and made more useful as follows:

function countup(yr, mon, d) {
  var montharray = [ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" ];
  var d = new Date(montharray[mon-1] + " " + d + ", " + yr);
  
  var today = new Date();
  today.setHours(0);
  today.setMinutes(0);
  today.setSeconds(0);
  today.setMilliseconds(0);
  //today is now set to the start of the day (midnight)

  var difference = Math.round( (today - d) / (24*60*60*1000) );//whole number of days from d to today.
  var ph    = Math.round(100 * Math.sin((2 * Math.PI / 23) * difference));
  var intel = Math.round(100 * Math.sin((2 * Math.PI / 33) * difference));
  var em    = Math.round(100 * Math.sin((2 * Math.PI / 28) * difference));
  var av    = Math.round( (ph + intel + em) / 3 );
  return {
    birthm : difference,
    ph : ph,
    intel : intel,
    em : em,
    av : av
  };
}

Call as follows:

var bioData = countup(1991, 6, 20);//20th June 1991
//The returned object (bioData) has properties .birthm, .ph, .intel, .em, and .av
//You can now do what you want with the values, eg :
alert([ bioData.birthm, bioData.ph, bioData.intel, bioData.em, bioData.av ]);

NOTES:

  • The function no longer relies on global variables for receiving data or for outputting its results. Instead, we pass integers (yyyy, mm, dd) to indicate the birth date and return an object containing the calculated data.
  • The method for setting today to midnight is fully cross-browser, without reliance on browser detection.
  • We also avoid the variable name int , which may be a reserved word. (Javascript has many reserved words, some of which are, strangely, not even included in the language).

Airshow

Edited by Airshow: n/a

0

Thinking about it, you don't even need to set today to midnight (as per the original code) because we can handle any remainder after dividing by (24*60*60*1000), with Math.floor() as opposed to Math.round() .

function countup(yr, mon, d) {
  var montharray = [ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" ];
  var d = new Date(montharray[mon-1] + " " + d + ", " + yr);
  
  var today = new Date();

  var difference = Math.floor( (today - d) / (24*60*60*1000) );//whole number of days from d to today.
  var ph    = Math.round(100 * Math.sin((2 * Math.PI / 23) * difference));
  var intel = Math.round(100 * Math.sin((2 * Math.PI / 33) * difference));
  var em    = Math.round(100 * Math.sin((2 * Math.PI / 28) * difference));
  var av    = Math.round( (ph + intel + em) / 3 );
  return {
    birthm : difference,
    ph : ph,
    intel : intel,
    em : em,
    av : av
  };
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.