Avatar billede wisemind Nybegynder
03. november 2008 - 18:34 Der er 7 kommentarer og
3 løsninger

Countup af kroner

Hej Eksperter,

Jeg skal bruge en counter som counter op i kroner, ala 1kr i sekundet.

Jeg har et script som tæller op fra en dato, det skal være ligesom den, blot med total antal kroner fra en given dag.

Paster scriptet nedenunder, håber det giver mening, og der er nogen som kan hjælpe! :)

På forhånd tak!

Scriptet der tæller op fra dato ser således ud:


<script language="JavaScript1.2">

//Dynamic countup Script- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

function setcountup(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE countup SCRIPT HERE//////////////////

//STEP 1: Configure the date to count up from, in the format year, month, day:
//This date should be less than today
setcountup(1999,3,2)

//STEP 2: Configure text to be attached to count up
var displaymessage="have passed since the debut of our site!"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countup area
var countupwidth='95%'
var countupheight='20px' //applicable only in NS4
var countupbgcolor='lightyellow'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countup(){
if (document.layers)
document.countupnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}

if (document.all||document.getElementById)
document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')

window.onload=start_countup


function countup(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(todaystring)-Date.parse(paststring)
dyear=Math.floor(dd/(60*60*1000*24*365)*1)
dmonth=Math.floor(dd/(60*60*1000*24*12)/(dyear*12))
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

if (document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+dyear+" years, "+dmonth+" months, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags)
document.countupnsmain.document.countupnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dyear+" years, "+dmonth+" months, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags

setTimeout("countup()",1000)
}
</script>

<ilayer id="countupnsmain" width=&{countupwidth}; height=&{countupheight}; bgColor=&{countupbgcolor}; visibility=hide><layer id="countupnssub" width=&{countupwidth}; height=&{countupheight}; left=0 top=0></layer></ilayer>
Avatar billede sirerugor Nybegynder
03. november 2008 - 21:55 #1
Sådan her kan det gøres..

<script language="JavaScript1.2">
var countupwidth='95%'
var countupheight='20px' //applicable only in NS4
var countupbgcolor='lightyellow'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'
var kr = 0
var crosscount=''

function start_countup(){
if (document.layers)
document.countupnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}

if (document.all||document.getElementById)
document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')

window.onload=start_countup

function countup(){
kr = kr+1

if (document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+kr+" kr."+closetags)
document.countupnsmain.document.countupnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+kr+" kr."+closetags

setTimeout("countup()",1000)
}
</script>

<ilayer id="countupnsmain" width=&{countupwidth}; height=&{countupheight}; bgColor=&{countupbgcolor}; visibility=hide><layer id="countupnssub" width=&{countupwidth}; height=&{countupheight}; left=0 top=0></layer></ilayer>
Avatar billede sirerugor Nybegynder
03. november 2008 - 22:02 #2
Og dette er så tilrettet det du egentligt skrev du ville have... Hehe. "xxxx kr. since..."

<script language="JavaScript1.2">

//Dynamic countup Script- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com

function setcountup(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE countup SCRIPT HERE//////////////////

//STEP 1: Configure the date to count up from, in the format year, month, day:
//This date should be less than today
setcountup(2008,11,3)

//STEP 2: Configure text to be attached to count up
var displaymessage="have passed since the debut of our site!"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countup area
var countupwidth='95%'
var countupheight='20px' //applicable only in NS4
var countupbgcolor='lightyellow'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countup(){
if (document.layers)
document.countupnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}

if (document.all||document.getElementById)
document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')

window.onload=start_countup


function countup(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(todaystring)-Date.parse(paststring)
dyear=Math.floor(dd/(60*60*1000*24*365)*1)
dmonth=Math.floor(dd/(60*60*1000*24*12)/(dyear*12))
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

if (document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+dd/1000+" kr. "+displaymessage+closetags)
document.countupnsmain.document.countupnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dd/1000+" kr. "+displaymessage+closetags

setTimeout("countup()",1000)
}
</script>

<ilayer id="countupnsmain" width=&{countupwidth}; height=&{countupheight}; bgColor=&{countupbgcolor}; visibility=hide><layer id="countupnssub" width=&{countupwidth}; height=&{countupheight}; left=0 top=0></layer></ilayer>
Avatar billede wisemind Nybegynder
04. november 2008 - 04:59 #3
Hey Sirerugor, tak for hjælpen, det er næsten perfekt!

Er det muligt at lave sådan at det kun tæller op hver 3. sekund og man kan indstille hvor meget den tæller op, f.eks. 0,5 i sekundet

På forhånd tak
Avatar billede sirerugor Nybegynder
04. november 2008 - 08:24 #4
JO, helt sikkert. Nu kan du indstille 'interval' i sekunder hvor tit den skal opdatere og 'increment' er hvor meget pr. sekund. :)

<script language="JavaScript1.2">
function setcountup(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

setcountup(2008,11,3)

var interval = 1 // interval in seconds
var increment = 0.5 // amount to increment at each second
var displaymessage="have passed since the debut of our site!"
var countupwidth='95%'
var countupheight='20px' //applicable only in NS4
var countupbgcolor='lightyellow'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'
var crosscount=''
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function start_countup(){
if (document.layers)
document.countupnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
countup()
}

if (document.all||document.getElementById)
document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')

window.onload=start_countup

function countup(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
paststring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(todaystring)-Date.parse(paststring)
dyear=Math.floor(dd/(60*60*1000*24*365)*1)
dmonth=Math.floor(dd/(60*60*1000*24*12)/(dyear*12))
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

if (document.layers){
document.countupnsmain.document.countupnssub.document.write(opentags+dd/1000*increment+" kr. "+displaymessage+closetags)
document.countupnsmain.document.countupnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dd/1000*increment+" kr. "+displaymessage+closetags

setTimeout("countup()",interval*1000)
}
</script>

<ilayer id="countupnsmain" width=&{countupwidth}; height=&{countupheight}; bgColor=&{countupbgcolor}; visibility=hide><layer id="countupnssub" width=&{countupwidth}; height=&{countupheight}; left=0 top=0></layer></ilayer>
Avatar billede wisemind Nybegynder
04. november 2008 - 09:01 #5
Du er for sej, det er perfekt!
Avatar billede sirerugor Nybegynder
04. november 2008 - 09:18 #6
Tak tak :) Du kan forresten fjerne dyear, dmonth, dhour, dmin og dsec siden de ikke bruges længere..
Avatar billede wisemind Nybegynder
04. november 2008 - 09:41 #7
Thanks for info! Jeg er en mongol til javascript, så lige en sidste ting her på falderebet: hvordan sætter man et punktum efter hver tredje ciffer ala 100.000.000 Så det bliver noget mere overskueligt?
Avatar billede sirerugor Nybegynder
04. november 2008 - 18:09 #8
Dette vil gøre som du ønsker.. :)

<script type="text/javascript">
function dottyfy(val){
  var pos;
  val=val.split(".").join("");
  var dot=val.indexOf(",");
  if(dot<0)dot=val.length;
  var r="";
  for(pos=dot-3;pos>=1;pos-=3)
    r="."+val.substr(pos,3)+r;
  r=val.substring(0,pos+3)+r;
  dot=val.indexOf(",");
  if(dot>0)r+=val.substring(dot);
  return r;
}

document.writeln(dottyfy("10000000"));
</script>

Fint nok?
Avatar billede roenving Novice
05. november 2008 - 08:22 #9
-- og en lille genial algoritme præsenteret i en tråd her:

function ins1000Sep(val){
  val = val.split(",");
  val[0] = val[0].split("").reverse().join("");
  val[0] = val[0].replace(/(\d{3})/g,"$1.");
  val[0] = val[0].split("").reverse().join("");
  val[0] = val[0].replace(/^(-?)\./,"$1");
  return val.join(",");
}
Avatar billede wisemind Nybegynder
05. november 2008 - 08:37 #10
lol jeg fatter ingenting, men ja det ser sgu genialt ud.

Roenving eller sirerugor: Hvordan får jeg det smidt ind i den oprindelige kode, så "count up"-taller inderholder . efter hver tredje ciffer?

Takker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester