I am creating site about Islam and muslims (www.islammuslim.lv) and I want that on site would be daily praying times. They changes day from day so I need unique for every day. On internet there is some 2-3 muslim portals who offers javascript code and they send to your site prayer times, but they do not give enough options for making it fit in design. So I am trying to create my self script in which I could wrote in those prayertimes. As far as I understand I need something like this: var now date = 14/03/2007 var now date = 15/03/2007 var now date = 16/03/2007 var now date = 17/03/2007 etc so if (or case) today = 14/03/2007 then display 04:33 06:43 12:33 15:34 18:24 20:24 so if (or case) today = 15/03/2007 then display 04:32 06:41 12:32 15:36 18:26 20:26 so if (or case) today = 16/03/2007 then display 04:30 06:40 12:32 15:38 18:28 20:28 so if (or case) today = 17/03/2007 then display 04:29 06:38 12:31 15:39 18:29 20:29 etc So how does it is in Javascript code?
Please let me know if I understood correctly: <script language="JavaScript"> var date = new Date(); var today = date.getFullYear() + '/' + date.getMonth() + '/' + date.getDate(); switch (today) { case '2007/2/15': document.write('04:33 06:43 12:33 15:34 18:24 20:24'); case '2007/2/16': document.write('04:33 06:43 12:33 15:34 18:24 20:24'); default: } </script> HTML:
Thanks. It is almost what I need. Almost, becouse it do not work properly. It creates both results so I get displayed: 04:33 06:43 12:33 15:34 18:24 20:2404:33 06:43 12:33 15:34 18:24 20:24 What could be problem?
Tried to edit and find the problem by "merging" with another similar script, but this do not work at all: <script language="JavaScript"> var nowdate = new Date(); var currDate = nowDate.getFullYear() + '/' + nowDate.getMonth() + '/' + nowDate.getDate(); switch (true) { case (currDate = '2007/2/15'): document.write('04:33 06:43 12:33 15:34 18:24 20:24'); case (currDate = '2007/2/16'): document.write('04:33 06:43 12:33 15:34 18:24 20:24'); default: } </script> Code (markup):
I don't really know how prayer times shift from day to day, but isn't there at least some sort of formula for it? The way you have it now you're going to either have to a) constantly update it or b) have a huge list of days. Just seems like a problem. Also, I've noticed with the code is that the dates are wrong. They're set to fire if it's February, not March. And you might want to put something in the default case.
what country are those number for ahmad ? rgchris no there is no formula , it depend on the sun (when it come on , when it come off , at noon , etc ...)
The break; statement is missing. Try this one: <script language="JavaScript"> var date = new Date(); var today = date.getFullYear() + '/' + date.getMonth() + '/' + date.getDate(); switch (today) { case '2007/2/15': document.write('04:33 06:43 12:33 15:34 18:24 20:24'); break; case '2007/2/16': document.write('04:33 06:43 12:33 15:34 18:24 20:24'); break; default: } </script> Code (markup):
There is some kind of astranomic calculation for longitutes and latitudes. I do not have such programm. Also there is difirence of opinion about Fajr (some time before sunrise. When first light is apearing) and Isha (early night, when sky loses its sunset redding). Those difirences of opinion is minimal, more important on which metodology is made calculation for far north and south areas for times when day is very long (not talking about polar days). Some say that You can take Iša right after Sunset prayer, some says 2 (or 1,5) houers, some calculates on partition between sunset and sunrise. So there is some difirences - but that is not so important, becouse I can just choose one. But still, that calculatin as I understand is not an option. More easy is to write in those numbers from calculation results. If I would put that script for some 2 months, it will not be such problem I think. As I understand that 0 is for january, 1 is for february and 2 is for march, so I think he is correct. But I will check. commandos: I`m from Latvia, ethnic latvian. Better to use php + mysql for the whole year . ---------- I do not like php. To complicated. My knowledge about scripting is very small, I just opened Frontpage only when I started to build my website.
opps I missed the break statement! Sorry Thanks Crenok! (Firefox JavaScript debugger did not warn me )
Yes, it is working. I noticed that there was no break and I add but this way (and it didnt work): case '2007/2/15': document.write('04:33 06:43 12:33 15:34 18:24 20:24'); break; case '2007/2/16': document.write('04:33 06:43 12:33 15:34 18:24 20:24'); break; default: Code (markup): I did not know that there must be empty space between them. Thanks. Thanks DeLaVega, ofcourse too. I spent truly many days and houers for trying to solve my prayingtime script problem.
You're welcome I think there's no need to have empty lines between them, it just a matter of make the code clearer and more readable It should work the same with or without them