JavaScript - Money Count Up - Possible?
Similar TutorialsHi , I need to do javascript money validation for a field. the condtions are 1) depending on the Locale (not sure if this can be done in JS like US,Germany..) 2) verify if it has $,pound symbol, yen symbol.. 3) group the digits either like 00,00,000 or 000,000,000 4) accept 2 digits decimal 000,000.00 cud some one help me with the code please? thanks function below will output price value in text field based on drop-menu option. It's working but I want it's always show value in 2 decimal point for variable 'price'. Can anyone help me with this problem? function findPrice() { if (document.getElementById("region").value == "blank") { var price = document.getElementById("price"); price.value = "<?php echo 'Choose your region to get the price'; ?>"; } if (document.getElementById("region").value == "Peninsular Malaysia") { var price = document.getElementById("price"); price.value= '<?php echo $PM_Price; ?>'; } if (document.getElementById("region").value == "Sabah/Labuan") { var price = document.getElementById("price"); price.value = '<?php echo $SL_Price; ?>'; } if (document.getElementById("region").value == "Sarawak") { var price = document.getElementById("price"); price.value = '<?php echo $SR_Price; ?>'; } } I've been looking everywhere for a script that counts up from 1 to 10, but can't find anything. I even searched the forums. Basically just something that starts from 1 and then replaces itself with 2, and so on. Thanks! Hi, I am not a Javascript programmer and I am facing some barriers. Maybe some of you could help me. I would need a script that can be used to count down until any given date with hour, minutes and seconds. For example: Quote: September 10, 2009 16:02:00 Bob Kuspe I would like to count how many duplicate values I have in an array. My below attempt doesnt count the duplicate values: Code: var ct = 0; for(var i = 0;i < myArray.length;i++) { var myData = getData[i].city; if(myData == myData) { ct++; } alert("Total Count = " + ct); } Please advise the best way to do this. Deleted
Hi, I want to do a redirect count so that the user can see the count going down. for example, I want them to be able to see the following. You will be redirected in 5 seconds. The user should be able to see the count going down from 5 to 4 to 3 to 2 to 1 and then they are redirected. I can get the page to redirect after 5 seconds but I want the user to be able to see it count down. Thanks in advance for your help hi i am new to javascript. i make a mcq quiz website in one of server side script. now for that website i want to make count down timer so when that quiz starts the user will have 5 minutes to complete that quiz if use does not able to complete quiz in given time then quiz should disable and shows the user score how can i achieve this I have a table that has multiple subtables built into it, I need to get a count of the number of rows only on the main table, I tried using document.getElementById('tableID').rows.length but that returns 91 rows (its reading all the subtables), the main table is built from a cold fusion page so the length of the table varies depending on your selection. I've been searching around for a bit but have had no luck, Any help would be appreciated. Hi All, Not sure if you can help, I'm having some issues with a count down timer that outputs a time until deadline. It was all working fine however since the clocks have gone back in the UK it is a hour out. However I was under the impression that the UTCHours called GMT time with the clocks going forward & backwards. - if this is not the case how do I call the correct GMT time or the server time? The server time is correct however the script displays the wrong message. Here is the script: [JavaScript] var lastimage = ""; function checkTimer() { function b(a, b, c) { - Pastebin.com Thanks! Hi, I am new here and am hoping for some guidance or a solution. Any help is greatly appreciated. I have a total count in a shopping cart stored from PHP as a cookie. I.E. compare[233], compare[324] (where the id is the item ID). I want to update the count of items in the cart in real time, so when the visitor clicks "Add", the count will update without reloading the page. Currently, I can get PHP to count the cookies, but not JS. The problem that I am having is that if the items are 7, and an item is added it will go to 8 correctly, if another item is added it goes to 14, not 9. This is the code that I have so far: Code: <?php $saved_ct = $number_of_items_already_in_cart; // # of cookies found or 'compare' I.E. 7 ?> <script type="text/javascript"> function increase(){ var i=<?php echo "$saved_ct"; ?>; i++; document.getElementById('i').innerHTML= + i; } </script> Cart: (<b id=\"saved_ct\">{$saved_ct}</b>) --- Item: <a href=\"#\" id=\"{$id}\" onclick=\"increase();return false\">Add to basket</a> Hi Guys, I have a javascript, which counts the specified words.. I want javascript to count some of the html tags and symbols when i enter a html code in the textarea.. - the below searchwords are not functioning properly. http://(space) http:/(space) etc... (no spaces are searching) - www. (.(dot) is not searching, also when i enter wwww(4 times) in the textarea it shows www. as count 1) - i can't enter the below symbols in searchwords array [ < ' ? I thank once again Bullant for helping me on the below script... But i am trying to fix my above issue and i couldn't.. :( Please help me out guys... Here is my Code... Code: <html> <head> <title>Word Count</title> <script type = "text/javascript"> function searchForWords(){ document.getElementById('resultsContainer').innerHTML = ''; var txt = document.getElementById('txtMsg').value; var strWords = document.getElementById('txtSearchWords').value; var searchWordsTokens = strWords.split(' '); var searchWords = ['href','LINK_ID','mailto','src="','src= ','src =','.jpg','.gif','.png','www','www.','http','http:// ','http:/ ','http: ','http ',' http',' "','@','amp;','TBD']; for(i=0; i < searchWordsTokens.length; i++){ if(searchWordsTokens[i].length > 0){searchWords.push(searchWordsTokens[i]);} //remove spaces between words } var results = [],matches; for(i=0; i < searchWords.length; i++){ var regex = new RegExp('\\b'+searchWords[i]+'\\b','gi'); matches = txt.match(regex); results[searchWords[i]] = (matches)? matches.length : 0; } //output results var str = ''; for(var i in results){ str += i+'--'+results[i]+'<br />'; } document.getElementById('resultsContainer').innerHTML = str; } window.onload=function(){ document.getElementById('form_submit').onclick=searchForWords; } </script> </head> <body> <table> <tr><td align="center"> <form id="contact_form"><h4>Paste your HTML Code he </h4> <p><label class="form_label" for='message'></label> <textarea rows="20" cols="60" id="txtMsg"></textarea> </p> <div> <input type="text" id="txtSearchWords"/> </div> <p><input id='form_submit' type="button" value="Check for Counts"></p> <div><p><input id='form_submit' type="reset" value="Clear"></p></div> <div id="resultsContainer"></div> </form><br /></td> </table> </body> </html> Hi, I have a JavaScript function which counts the number of checkboxes in a form, it then counts the number of checked checkboxes, it then calculates a percentage based on the number of checkboxes checked. The problem I have is that if there is only one checkbox in the form (record from the db) then the JS function does not work. Code: //function to check total number of GREEN CheckBoxes checked function countChecksGreen(form) { //initialize total count to zero var totalChecked = 0; //get total number of CheckBoxes in form var chkBoxCount = examsetting.checkboxgreen.length; //loop through each CheckBox for (var i = 0; i < chkBoxCount; i++) { //check the state of each CheckBox if (eval("document.examsetting.checkboxgreen[" + i + "].checked") == true) { //it's checked so increment the counter totalChecked += 1; } } //return the number of checked var greenElement = document.getElementById('green'); var green = greenElement.innerHTML; var percentage = totalChecked/<?php echo $exam['questions']; ?>*100; greenElement.innerHTML = Math.round(percentage*10)/10; } Any help would be appreciated. The clock should be counting up from January 27, 2012 03:26:00, but for some reason its reading as 3 days having passed instead of the 5 days...My thoughts are that the mistake is in this section of code, because it seems to have counted January as 29 days instead of 31 Code: function CountUp(initDate, id){ * * this.beginDate = new Date(initDate); * * this.countainer = document.getElementById(id); * * this.numOfDays = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; * * this.borrowed = 0, this.years = 0, this.months = 0, this.days = 0; * * this.hours = 0, this.minutes = 0, this.seconds = 0; * * this.updateNumOfDays(); * * this.updateCounter(); } * CountUp.prototype.updateNumOfDays=function(){ * * var dateNow = new Date(); * * var currYear = dateNow.getFullYear(); * * if ( (currYear % 4 == 0 && currYear % 100 != 0 ) || currYear % 400 == 0 ) { this.numOfDays[1] = 29; } But having no experience with Java, this is just a guess...Here's ALL the other info you could need... Here's the Web address the Clock is on: http://nvctruth.com/majorgale/ (i've got to figure out the background on a separate day) And Here is the FULL Code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>JavaScript CountUp Timer - Praveen Lobo</title> <script type="text/javascript"> function CountUp(initDate, id){ * * this.beginDate = new Date(initDate); * * this.countainer = document.getElementById(id); * * this.numOfDays = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; * * this.borrowed = 0, this.years = 0, this.months = 0, this.days = 0; * * this.hours = 0, this.minutes = 0, this.seconds = 0; * * this.updateNumOfDays(); * * this.updateCounter(); } * CountUp.prototype.updateNumOfDays=function(){ * * var dateNow = new Date(); * * var currYear = dateNow.getFullYear(); * * if ( (currYear % 4 == 0 && currYear % 100 != 0 ) || currYear % 400 == 0 ) { * * * * this.numOfDays[1] = 29; * * } * * var self = this; * * setTimeout(function(){self.updateNumOfDays();}, (new Date((currYear+1), 1, 2) - dateNow)); } * CountUp.prototype.datePartDiff=function(then, now, MAX){ * * var diff = now - then - this.borrowed; * * this.borrowed = 0; * * if ( diff > -1 ) return diff; * * this.borrowed = 1; * * return (MAX + diff); } * CountUp.prototype.calculate=function(){ * * var currDate = new Date(); * * var prevDate = this.beginDate; * * this.seconds = this.datePartDiff(prevDate.getSeconds(), currDate.getSeconds(), 60); * * this.minutes = this.datePartDiff(prevDate.getMinutes(), currDate.getMinutes(), 60); * * this.hours = this.datePartDiff(prevDate.getHours(), currDate.getHours(), 24); * * this.days = this.datePartDiff(prevDate.getDate(), currDate.getDate(), this.numOfDays[currDate.getMonth()]); * * this.months = this.datePartDiff(prevDate.getMonth(), currDate.getMonth(), 12); * * this.years = this.datePartDiff(prevDate.getFullYear(), currDate.getFullYear(),0); } * CountUp.prototype.addLeadingZero=function(value){ * * return value < 10 ? ("0" + value) : value; } * CountUp.prototype.formatTime=function(){ * * this.seconds = this.addLeadingZero(this.seconds); * * this.minutes = this.addLeadingZero(this.minutes); * * this.hours = this.addLeadingZero(this.hours); } * CountUp.prototype.updateCounter=function(){ * * this.calculate(); * * this.formatTime(); * * this.countainer.innerHTML ="<strong>" + this.years + "</strong> <small>" + (this.years == 1? "year" : "years") + "</small>" + * * * * " <strong>" + this.months + "</strong> <small>" + (this.months == 1? "month" : "months") + "</small>" + * * * * " <strong>" + this.days + "</strong> <small>" + (this.days == 1? "day" : "days") + "</small>" + * * * * " <strong>" + this.hours + "</strong> <small>" + (this.hours == 1? "hour" : "hours") + "</small>" + * * * * " <strong>" + this.minutes + "</strong> <small>" + (this.minutes == 1? "minute" : "minutes") + "</small>" + * * * * " <strong>" + this.seconds + "</strong> <small>" + (this.seconds == 1? "second" : "seconds") + "</small>"; * * var self = this; * * setTimeout(function(){self.updateCounter();}, 1000); } * window.onload=function(){ new CountUp('January 27, 2012 03:26:00', 'counter'); } * </script> </head> I've reading this forum for some time now and this is my first post. I hope to find an helpfull community here and to be able to help other users myself. I'm new to JS so this might be an simple question: I have an form that can be filled bij an user, some fields are calculated by Javascript. I need an code to be able to calculate 'live' the totals of the fields in the loop, that fields are the grey fields at the borro. This is (part of) my form: PHP Code: <table align="center" class="bd" border="0" cellspacing="1" cellpadding="2" width="500"> <tr> <td>Bewerking</td> <td>Prijs per uur</td> <td>Aantal uur</td> <td align="center">Totaal</td> <td>Opmerkingen</td> </tr> <?php for ($i=0; $i<=$bew_aantal_regels_corr; $i++) { ?> <tr> <td><?php if($error_bew_vergeten[$i] == "ja"){ $error_omschr = $error_omschr_bew_vergeten[$i]; include('includes/input_error.php'); } ?> <select name="bewerking[]" onChange="bew_uren(this, <?php echo $i ?>),bew_uren_tot(this, <?php echo $i ?>)"> <option></option> <?php $sql_bewerking = "SELECT omschrijving, tarief from sp_calc_werkzaamheden ORDER BY omschrijving ASC"; $res_bewerking = mysql_query($sql_bewerking,$con); while ($row_bewerking = mysql_fetch_assoc($res_bewerking)){ ?> <option <?php if($row_bewerking["omschrijving"] == $bew_omschr[$i]){ echo 'selected="selected"'; } ?> value=<?php echo $row_bewerking["tarief"] ?>><?php echo $row_bewerking["omschrijving"] ?></option> <?php } ?></select> <input type="hidden" name="bew_omschr[]" value="<?php if($bew_omschr[$i] != ''){ echo $bew_omschr[$i]; } ?>" /> </td> <td><input type="text" name="bew_tarief[]" onKeyup="bew_uren_tot(this, <?php echo $i ?>)" size="5" style="text-align:right" value="<?php if($bew_tarief[$i] != ''){ echo $bew_tarief[$i]; } ?>" /><?php if($error_bew_tarief[$i] == "ja"){ $error_omschr = $error_omschr_bew_tarief[$i]; include('includes/input_error.php'); } ?></td> <td><input type="text" name="bew_uren[]" onKeyup="bew_uren_tot(this, <?php echo $i ?>)" size="5" style="text-align:right" value="<?php if($bew_uren[$i] != ''){ echo $bew_uren[$i]; } ?>" /><?php if($error_bew_uren[$i] == "ja"){ $error_omschr = $error_omschr_bew_uren[$i]; include('includes/input_error.php'); } ?></td> <td><input type="text" name="bew_totaal[]" size="10" style="text-align:right;background-color: #f1f1f1" value="<?php if($bew_totaal[$i] != ''){ echo $bew_totaal[$i]; } ?>" readonly="readonly" /></td> <td><input type="text" name="bew_opmerkingen[]" size="75" value="<?php if($bew_opmerkingen[$i] != ''){ echo $bew_opmerkingen[$i]; } ?>" /></td> <td><input type="hidden" name="bew_id[]" value="<?php if($bew_id[$i] != ''){ echo $bew_id[$i]; } ?>" /></td> </tr> <?php } ?> <tr> <td>Regels: <input type="text" name="bew_regels" value="<?php if($bew_aantal_regels != ''){ echo $bew_aantal_regels; } ?>" size="3" /><?php if($error_bew_aantal_regels == "ja"){ $error_omschr = $error_omschr_bew_aantal_regels; include('includes/input_error.php'); } ?> <input type="hidden" name="bew_aantal_regels_oud" value="<?php if($bew_aantal_regels_oud != ''){ echo $bew_aantal_regels_oud; } ?>" size="3" /> <input type="hidden" name="bew_aantal_regels_db" value="<?php if($bew_aantal_regels_db != ''){ echo $bew_aantal_regels_db; } ?>" size="3" /></td> <td></td> <td><input type="text" name="bewerking_tot_uur" size="5" style="text-align:right;background-color: #f1f1f1"" value="<?php if($bewerking_tot != ''){ echo $bewerking_tot; } ?>" readonly="readonly" /></td> <td><input type="text"name="bewerking_tot" size="10" style="text-align:right;background-color: #f1f1f1"" value="<?php if($bewerking_tot_uur != ''){ echo $bewerking_tot_uur; } ?>" readonly="readonly" /></td> </tr> </table> Hee guys, I've got a little bit of a problem on my hand. Someone has asked me to help them on a FREE forum host. You have no access to PHP or SQL or anything like that. Just the templates, but even those are really messy! Now on the navagation bar there a PM section (obviously) but the wording they have used is very long and ugly. I was wondering if it would be possible to change the wording whilst still having it show the amount of PM's that you have. If you need anymore information just ask, but I really hope someone can help Hello, I have this script (which i didn't program) which is suppose to count down an amount of time, and then redirect the page to another place. It works fine on IE/Opera but it doesn't on Netscape/Mozilla. I was wondering if any one could tell me the couse or another script that will work on most browsers. Thanks a lot Code: time_in_sec = 300; function nextSec() { m = Math.floor(time_in_sec / 60); s = time_in_sec % 60; if (s < 10) { s = "0" + s; } if ((m == 0)&&(s == 0)) { location.replace("SOME_URL"); } else { document.all.counter.innerHTML = '<font style="font-size: 13pt" color="#999999">' + m + ":" + s + "</font>"; window.setTimeout('nextSec()',1000); } time_in_sec--; } Hello all i'm stuck on the last part of my program. Basically it will generate the score and players position but it will no show the following: I'm also having trouble stopping the loop from going over 80 Now add code to your program which will: ! declare and initialise a variable to keep count of how many goes the player takes to get out; ! add one to this count every time the loop is repeated; ! write out the count in a suitable message at the end. Any help is very much appreciated. [CODE] var countMoves = 0; while (playersPosition <80) { playersScore = rollDie(); document.write('Sco ' + playersScore); playersPosition = playersScore + playersPosition; document.write(' squa ' + playersPosition); indexOfNumber = findIndexOf(playersPosition, specialSquaresArray); if (indexOfNumber != -1) { document.write(' ladder to square ' + connectedSquaresArray[indexOfNumber]); document.write('<BR>'); document.write('Sco ' + playersScore); playersScore = connectedSquaresArray[indexOfNumber] + playersScore; document.write(' squa ' + playersScore); playersPosition = playersScore; } document.write('<BR>'); } for (count =1; count <=array.length; count = count + 1) if(array[count] > array[countMoves]) { countMoves = count; } document.write('it took ' + indexOfNumber + 'goes to get out'); [CODE] I'm trying to make a count-up timer that counts to 100 or 1000 then adds 1 to another number. i would like the timer speed to be adjustable if possible...i'm kinda new to javascript so any help with this would be appreciated. |