JavaScript - How To Display Trailing Zero's After Multiplication
I have javascript function which calculates the product of two numbers.
function fnCalculate() { var lat1=price * num; } Here for eg if price is 19.50 and num is 1 then o/p should be 19.50 and not 19.5 as its resturning now. Also if price is 15.00 and num is 1 then o/p should be 15.00 and no just 15. Is it possible ... someone please help Similar TutorialsHello all is it possible to strip leading (meaning at the VERY begining of the text) and trailing (anything at the end of the text) carriage returns with reg ex? so if smbody enters return return return start txt entry ----> keep all other returns in paragraph sloppy ending retrun return return it would remove the start and end returns I'd like to add it to this if possible. Code: comts = comts.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces low tech (validation script done trying to improve on it now) I am trying to allow the user to type in two numbers and then a multiplication table pops up below it. It works however I cannot figure out how to make the first row be 0,1,2,3,4,5..ect and same for the first column in each row going down the table. Here is my code.. Code: <html> <head> <title>Untitled</title> <script> function f(x,y) { if((x < 3) || (y < 3) || (x > 10) || (y > 10)){ alert("Please enter numbers between 3 and 7") }else{ s = "<table border = '1'>" var total; for (i=0; i<=x; i++){ s+= "<tr></tr>"; for (j=0; j <= y; j++){ total = i * j; s+="<td>"+ total +"</td>" } } s+="</table>" document.getElementById("Q").innerHTML+=s } } </script> </head> <body> [enter a number between 3 and 10] <form id = "form1"> <input id = "a" value = "6"> by <input id = "b" value = "8"><br> <input type = "button" onclick = "f(a.value,b.value)" value = "Click here when ready!"> <br> </form> <div id = "Q"></div> </body> </html> Hi, I am having a hard time to display a table with user preference of how many rows/columns to create a multiplication table. I think I have to user DOM but I am not sure and I am not sure how to use it. My question is, how do I get the user input to use as a dynamic array input in a for loop so I can create the multiplication table using CSS ? Here is my code: [CODE] Hi, I am having a hard time to display a table with user preference of how many rows/columns to create a multiplication table. I think I have to user DOM but I am not sure and I am not sure how to use it. My question is, how do I get the user input to use as a dynamic array input in a for loop so I can create the multiplication table using CSS ? Here is my code: Code: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Multiplication table web page </title> <style type="text/css"> h2 {text-align: center;} table {position:absolute;left:300px;} </style> </head> <body> <h2>Multiplication Table</h2> <script type="text/javascript"> <!-- var size; do { size = prompt("What size table do you want?","10"); } while ((size < 1) || (size > 15)); document.write("<table border=\"5\" cellpadding=\"5\" cellspacing=\"5\">"); document.write("<tr><th> *</th>"); for(var i = 0; i < 10; i++) { for(var j = 0; j < 10; j++) { size = i * j; } } document.write("</table>"); // --> </script> </body> </html> Hello, I am trying to write a javascript page that shuffles an array of questions ( 1x1 , 1x2, 1x3 - 1x12), prints them, then has the user type in the answer, then checks them to make sure the user answer is correct. I have looked up a lot of source code for javascript "quiz" but they all are multiple choice answers and the questions are not shuffled. This is as far as I have gotten, but now I am not sure how to take the user input text and compare them to the answer / question array to make sure to check. Code: <html> <head> <title> Slick Math </title> <script type="text/javascript"> var quest = new Array; var ans = new Array; var questprint = new Array; quest[0] = "1 x 1 "; quest[1] = "1 x 2 "; quest[2] = "1 x 3 "; quest[3] = "1 x 4 "; quest[4] = "1 x 5 "; quest[5] = "1 x 6 "; quest[6] = "1 x 7 "; quest[7] = "1 x 8 "; quest[8] = "1 x 9 "; quest[9] = "1 x 10 "; quest[10] = "1 x 11 "; quest[11] = "1 x 12 "; questprint[0] = quest[0]+"<input type='text' name='q0'></input><br/>"; questprint[1] = quest[1]+"<input type='text' name='q1'></input><br/>"; questprint[2] = quest[2]+"<input type='text' name='q2'></input><br/>"; questprint[3] = quest[3]+"<input type='text' name='q3'></input><br/>"; questprint[4] = quest[4]+"<input type='text' name='q4'></input><br/>"; questprint[5] = quest[5]+"<input type='text' name='q5'></input><br/>"; questprint[6] = quest[6]+"<input type='text' name='q6'></input><br/>"; questprint[7] = quest[7]+"<input type='text' name='q7'></input><br/>"; questprint[8] = quest[8]+"<input type='text' name='q8'></input><br/>"; questprint[9] = quest[9]+"<input type='text' name='q9'></input><br/>"; questprint[10] = quest[10]+"<input type='text' name='q10'></input><br/>"; questprint[11] = quest[11]+"<input type='text' name='q11'></input><br/>"; var score = 0; ans[0] = 1; ans[1] = 2; ans[2] = 3; ans[3] = 4; ans[4] = 5; ans[5] = 6; ans[6] = 7; ans[7] = 8; ans[8] = 9; ans[9] = 10; ans[10] = 11; ans[11] = 12; function shuffle() { return (Math.round(Math.random())-.5); } questprint.sort(shuffle); </script> </head> <body> <h1>Slick Math</h1> <form name="form"> <script type="text/javascript"> document.write(questprint[0]); document.write(questprint[1]); document.write(questprint[2]); document.write(questprint[3]); document.write(questprint[4]); document.write(questprint[5]); document.write(questprint[6]); document.write(questprint[7]); document.write(questprint[8]); document.write(questprint[9]); document.write(questprint[10]); document.write(questprint[11]); </script> </form> </body> </html> Thanks =] Ok, just to be honest this is for my assignment from my University, I have completed the whole code myself I just can't seem to get just one little thing. Code: function GenerateTables(){ var start = document.tables.start.value; var end = document.tables.end.value; var size = document.tables.size.value; for (start; start <= end; start++) { document.write("<table width='100' align='center'>") document.write("<caption><b>Table of </b>" + start + "</caption><br>") document.write("</table><br>") for (var i = 1; i <= size; i++) { document.write("<table border=1 align='center'>") document.write("<tr height=40 align='center'>") document.write("<td width=40 align='center'>" + start + "</td>") document.write("<td width=40 align='center'> * </td>") document.write("<td width=40 align='center'>" + i + "</td>") document.write("<td width=40 align='center'> = </td>") document.write("<td width=40 align='center'>" + start * i + "</td>") document.write("</tr>") document.write("</table>") } } } The function generates multiplication tables depending on the input user provides using this interface (given below). And it generates them like this (given below). Now what I want is to generate those tables sideways not downwards. Not all the tables, but it should complete one table downwards, then start the new table on its side. I can't seem to figure out anything that would make that happen, and ideas would be appreciated, thanks. Regards, Papichoolo. Hello, Could someone help me with this problem? I'd like the posted result to be a number with two decimals. I know how to make this normally but not with this kind of script. Thanks very much in advance! Code: <html> <head> <script type="text/javascript"> function calcResult(){ document.getElementById('result').innerHTML = ''; var num1 = newNumber(document.getElementById('txt1').value); var num2 = 0.429; var num3 = 1; if(isNaN(num1) || isNaN(num2)){ alert('Please enter a number'); } else { document.getElementById('result').innerHTML = num1 * num2; document.getElementById('entry').innerHTML = num1 * num3; } } window.onload=function(){ document.getElementById('btnCalc').onclick = calcResult; document.getElementById('btnCalc').onclick = calcEntry; } </script> </head> <body> <p> <input type="text" id="txt1" size="5" value="" maxlength="5" /> <button id="btnCalc">Calculate</button> </p> <p> <span id="entry"></span> × 0.429 = <span id="result"></span> </p> </body> </html> I'm trying to set an if statement so if one element is set to display:none, another element(s) sets margin-left to a certain number of pixels. Sort of like this (however, it's not working): Code: <script> if (document.getElementById('#why-choose-content').style.display = 'none') { document.getElementById('#always-content').style.margin-left = '335px'; } </script> Here is the site in question: http://bit.ly/8XfM0Q You can get a better idea of what I mean by clicking the 'plus' icons for the three colored tabs above the main content. Or if anybody has a more elegant way to get the divs to toggle under their respective headers, I'd love to hear. Thank you. Why isnt this working? Code: function display_form(obj) { var button_name = obj.id.split("dialog_"); var t = document.getElementById(button_name[1] + '_form').style.visibility = 'visible'; alert(t); } IE is saying: Code: id is 'null' or not an object Hi. this is my code for a form i am working on, i want it so that when "Non_Conformance_Type" = ID1 that <tbody id="ID1" style="display: none;"> </tbody> is displayed. Code: <script type="text/javascript"> // <![CDATA[ function display(obj,id1,id2,id3,id4,id5,id6,id7,id8) { txt = obj.options[obj.selectedIndex].value; document.getElementById(id1).style.display = 'none'; document.getElementById(id2).style.display = 'none'; document.getElementById(id3).style.display = 'none'; document.getElementById(id4).style.display = 'none'; document.getElementById(id5).style.display = 'none'; document.getElementById(id6).style.display = 'none'; document.getElementById(id7).style.display = 'none'; document.getElementById(id8).style.display = 'none'; if ( txt.match(id1) ) { document.getElementById(id1).style.display = 'block'; } if ( txt.match(id2) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id3) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id4) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id5) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id6) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id7) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id8) ) { document.getElementById(id2).style.display = 'block'; } } // ]]> </script> and... Code: <div id='Type_Non_Conformance_container'> <select name='Type_Non_Conformance' id='Type_Non_Conformance' size='1' onchange="display(this,ID1,ID2,ID3,ID4,ID5,ID6,ID7,ID8)"> <option value='' %Type_Non_Conformance%></option> <option value='ID1' %e89cf9a575493ea05184443c64bf031d%>Can Not Locate Product</option> <option value='ID2' %4cf35d2927674904ba13019f94f16827%>Can Not Locate Email</option> <option value='ID3' %8939f9a23e7bc218f93e8b223a364924%>Item Adjustment</option> <option value='ID4' %27c35559235fb503e7fba0f1896cd4f2%>Missing Shipping Instructions</option> <option value='ID5' %304931fb92d418057887a6b0727d83e7%>Partial Shippment Release</option> <option value='ID6' %76bf955f6d4ce8498b71b82d16c656a9%,>Lost Sale</option> <option value='ID7' %f7fa215ea76de432e1c83d283441c798%>Transfer/Order Did Not Ship</option> <option value='ID8' %b6ed7f7429483a76bc42a5b26a1bbb3e%>Other</option> </select> </div> and... Code: <tbody id="ID1" style="display: none;"> <div id='heading_container'> <div id='heading'>Can Not Locate Product</div> </div> <div id='Order_Transfer_Number_1_ID1_container'> <input type='text' name='Order_Transfer_Number_1_ID1' id='Order_Transfer_Number_1_ID1' value='%Order_Transfer_Number_1_ID1%' size='20' class='sfm_textbox'/> </div> <div id='Order_Transfer_Number_2_ID1_container'> <input type='text' name='Order_Transfer_Number_2_ID1' id='Order_Transfer_Number_2_ID1' value='%Order_Transfer_Number_2_ID1%' size='20' class='sfm_textbox'/> </div> <div id='label8_container'> <label id='label8' for='Order_Transfer_Number_1_ID1' class='sfm_form_label'>Order/Transfer #</label> </div> <div id='label9_container'> <label id='label9' for='Order_Transfer_Number_2_ID1' class='sfm_form_label'>-</label> </div> <div id='Taker_Number_ID1_container'> <input type='text' name='Taker_Number_ID1' id='Taker_Number_ID1' onkeypress='return sfm_decimal_key_handler(this, event,".")' value='%Taker_Number_ID1%'/> </div> <div id='label7_container'> <label id='label7' for='Taker_Number_ID1' class='sfm_form_label'>Taker #</label> </div> <div class='element_label' id='Order_Transfer_ID1_0_container'><input type='radio' name='Order_Transfer_ID1' id='Order_Transfer_ID1_radio_0' value='Order' %24304b44337785c961add086070b3981%/><label for='Order_Transfer_ID1_radio_0' class='element_label' id='Order_Transfer_ID1_radio_0_label'>Order</label></div> <div class='element_label' id='Order_Transfer_ID1_1_container'><input type='radio' name='Order_Transfer_ID1' id='Order_Transfer_ID1_radio_1' value='Transfer' tabindex='1' %9b4d481b434f7128f666cbc9a19d7c7a%/><label for='Order_Transfer_ID1_radio_1' class='element_label' id='Order_Transfer_ID1_radio_1_label'>Transfer</label></div> <div id='label10_container'> <label id='label10' for='Product_Number_ID1' class='sfm_form_label'>Part #</label> </div> <div id='Picker_Name_Last_ID1_container'> <input type='text' name='Picker_Name_Last_ID1' id='Picker_Name_Last_ID1' value='%Picker_Name_Last_ID1%' size='20' class='sfm_textbox'/> </div> <div id='Product_Number_ID1_container'> <input type='text' name='Product_Number_ID1' id='Product_Number_ID1' value='%Product_Number_ID1%' size='20' class='sfm_textbox'/> </div> <div id='Picker_Name_First_ID1_container'> <input type='text' name='Picker_Name_First_ID1' id='Picker_Name_First_ID1' value='%Picker_Name_First_ID1%' size='20' class='sfm_textbox'/> </div> <div id='label11_container'> <label id='label11' for='Picker_Name_First_ID1' class='sfm_form_label'>Picker Name</label> </div> <div id='label12_container'> <label id='label12' for='Picker_Name_First_ID1' class='sfm_form_label'>Last</label> </div> <div id='label13_container'> <label id='label13' for='Picker_Name_First_ID1' class='sfm_form_label'>First</label> </div> <div id='label15_container'> <label id='label15' for='Actions_ID1' class='sfm_form_label'>Actions To Be Taken</label> </div> <div id='Actions_ID1_container'><textarea name='Actions_ID1' id='Actions_ID1' cols='50' rows='8' class='sfm_textarea'>%Actions_ID1%</textarea></div> <div id='label14_container'> <label id='label14' for='Comments_ID1' class='sfm_form_label'>Comments</label> </div> <div id='Comments_ID1_container'><textarea name='Comments_ID1' id='Comments_ID1' cols='50' rows='8' class='sfm_textarea'>%Comments_ID1%</textarea></div> <div class='element_label' id='Picker_Confirm_ID1_container'><input type='checkbox' name='Picker_Confirm_ID1' id='Picker_Confirm_ID1' value='Yes' %4e8c663c6495851abfac06ef48a73f85%/><label for='Picker_Confirm_ID1' class='element_label' id='Picker_Confirm_ID1_label'>Picker Confirm Action Is Done</label></div> <div id='Screen_Clipping_ID1_container'> <input type='file' name='Screen_Clipping_ID1' id='Screen_Clipping_ID1'/> </div> <div id='label16_container'> <label id='label16' class='sfm_form_label'>Upload Any Screen Clippings</label> </div> </tbody> Please help, Thanks! All, If a user is going to my site with IE7 or less I call the following JS file. Code: // JavaScript Document var ie6_warning=navigator.userAgent.indexOf('MSIE 6') if (ie6_warning > 0) { document.write("<div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative; z-index:5000'> <div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display=\"none\"; return false;'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-cornerx.jpg' style='border: none;' alt='Close this notice'/></a></div> <div style='width: 740px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'> <div style='width: 75px; float: left;'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-warning.jpg' alt='Warning!'/></div> <div style='width: 275px; float: left; font-family: Arial, sans-serif; color:#000'> <div style='font-size: 14px; font-weight: bold; margin-top: 12px; color:#000'>You are using an outdated browser</div> <div style='font-size: 12px; margin-top: 6px; line-height: 12px; color:#000'>For a better experience using this site, please upgrade to a modern web browser.</div> </div><div style='width: 75px; float: left;'><a href='http://www.firefox.com' rel="nofollow" target='_blank'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div><div style='width: 75px; float: left;'><a href='http://www.browserforthebetter.com/download.html' rel="nofollow" target='_blank'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-ie8.jpg' style='border: none;' alt='Get Internet Explorer 8'/></a></div> <div style='width: 73px; float: left;'><a href='http://www.apple.com/safari/download/' rel="nofollow" target='_blank'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div> <div style='float: left; width: 73px;'><a href='http://www.google.com/chrome' rel="nofollow" target='_blank'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div><div style='float: left;'><a href='http://www.opera.com/' rel="nofollow" target='_blank'><img src='http://info.template-help.com/files/ie6_warning/ie6nomore-opera.jpg' style='border: none;' alt='Opera'/></a></div> </div></div>" );} Right now it only goes 75pixels. How can I make it so that it spans the whole screen of the users computer? Thanks in advance! [Hi all! I am obviously new to Javascript, blah blah blah, etc ... Please help me by pointing out what is wrong with my code while changing as little as possible ... and if you could also please explain the part that says t = total( parseFloat(a,10), parseFloat(b,10), parseFloat(c,10), parseFloat(d,10)); if(!isNaN(t)) f.value = t; as I copied that portion from someone and I really don't understand it. Thank you soooo much!] <html> <head> <title>Problem 3</title> <style type="text/css"> body { background-color:blue; font-family:verdana; font-size:large; } input { width: 60px; } </style> <script type="text/javascript"> var f = (a*0.1)+(b*0.15)+(c*0.25)+(d*0.2)+(e*0.3) if ( grade5Obj.value.length < 1 ) alert("Please enter a grade in every box!"); else displayObj.value=ourText + nameObj.value + '!'; }; function update() var a = document.getElementById( 'grade1' ).value, b = document.getElementById( 'grade2' ).value, c = document.getElementById( 'grade3' ).value, d = document.getElementById( 'grade4' ).value, e = document.getElementById( 'grade5' ).value, f = document.getElementById( 'ans' ), t=0; t = total( parseFloat(a,10), parseFloat(b,10), parseFloat(c,10), parseFloat(d,10)); if(!isNaN(t)) f.value = t; </script> </head> <body> <form action="" method="post"> <p>Enter the first grade <input id="grade1" onkeyup="update()"><br> <p>Enter the second grade <input id="grade2" onkeyup="update()"><br> <p>Enter the third grade <input id="grade3" onkeyup="update()"><br> <p>Enter the fourth grade <input id="grade4" onkeyup="update()"><br> <p>Enter the fifth grade <input id="grade5" onkeyup="update()"><br> <p>Your final grade is <input name="finalGrade" readonly="true"> <input type="button" value="Click me!" onclick="finalGrade value=document.getElementById( 'ans' )"></p> </form> </body> </html> Hi, I am trying to have an array of pictures rotating among them every 300 milliseconds. I am having a hard time to walk through the arrays to set new x and y values and rotate them to the new place. I think I have problems with my display code, where I should display the new position every time I call settimeout, exchanging the positions x and y from the array indexes position. There is my code: Code: <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>hexagonal array</title> <script type="text/javascript"> <!-- var pixArray = Array(6); function shiftPix(element, count, index) { var pi = 3.1415926535; // left: x coordinate, top: y coordinate y = 300 + 150 * Math.cos(2 * pi * (count + index)/6); x = 300 + 150 * Math.sin(2 * pi * (count + index)/6); element.style.left = x + "px"; element.style.top = y + "px"; } function display() { for (j = 0; j < 6 ; j++) { setTimeout("shiftPix(" + x + ", " + y + ")", 300); counter++; shiftPix(pixArray[j], counter, j); } } // --> </script> </head> <body> <h3>Hexagonal Array </h3> <div id="John" style="position:absolute;left:300px;top:450px"> <img src="picture1.jpg" alt="John Santore" width="90" height="120" /> </div> <div id="Seikyung" style="position:absolute;left:430px;top:375px"> <img src="picture2.jpg" alt="Seikyung Jung" width="90" height="120" /> </div> <div id="Glenn" style="position:absolute;left:430px;top:225px"> <img src="picture3.jpg" alt="Glenn Pevlicek" width="90" height="120" /> </div> <div id="Lee" style="position:absolute;left:300px;top:150px"> <img src="picture4.jpg" alt="Lee Mondshein" width="90" height="120" /> </div> <div id="Abdul" style="position:absolute;left:170px;top:225px"> <img src="picture5.jpg" alt="Abdul Sattar" width="90" height="120" /> </div> <div id="Toby" style="position:absolute;left:170px;top:375px"> <img src="picture6.jpg" alt="Toby Lorenzen" width="90" height="120" /> </div> <script type="text/javascript"> <!-- var counter = 0; pixArray[0] = document.getElementById("John"); pixArray[1] = document.getElementById("Seikyung"); pixArray[2] = document.getElementById("Glenn"); pixArray[3] = document.getElementById("Lee"); pixArray[4] = document.getElementById("Abdul"); pixArray[5] = document.getElementById("Toby"); display(); // --> </script> </body> </html> Hi, I'm just the custom scrollbar javascript 'Flexcroll' to customise div scrollbars on my website. However the section of my website I'm using this on has 'tabbed divs'. Ie. I'm hiding some div's using 'display:none;' then using javascript to change their state to 'display:block;' It seems if the div im attaching the 'Flexcroll' scrollbar to is initially 'display:none' then this scrollbar doesn't work when its shown on the page. Has anyone come across this issue before, and if so what was your solution? Any help, much appreciated! Thanks Curt I would like to display the elements in my array but it is NOT working. Here's my code: Code: <HTML> <HEAD> <TITLE>Test Input</TITLE> <script type="text/javascript"> function addtext() { var openURL=new Array("http://google.com","http://yahoo.com","http://www.msn.com","http://www.bing.com"); document.writeln('<table>'); for (i=0;i<=openURL.length-1;i++){ document.writeln('<tr><td>openURL[i]</td></tr>'); } document.writeln('</table>'); } </script> </HEAD> <body onload="addtext()"> </BODY> </HTML> Here's the ouput: Code: openURL[i] openURL[i] openURL[i] openURL[i] It should display: Code: http://google.com http://yahoo.com http://msn.com http://bing.com Any comments or suggestions are greatly apprecitated. thanks Hi, I have an application wherein for one page I want to display a Listbox on selection of a radio button. There should be 2 radio buttons and when the user clicks on the 2nd one "My Process", a list box should be displayed with several options. Can anybody pls help me with this as I'm a beginner to JS.. Many thanks Pooja. Hello everyone. I'm using the script Old Pedant posted here (huge thanks man!), however, I'm looking to have the timer display six numbers at all times. For example: If the timer has 15 hours, 35 minutes, and 10 seconds left it is currently displaying as: 15:35:10 - Perfect! If the timer has 5 hours, 35 minutes, and 10 seconds left it is currently displaying as: 5:35:10 - Humm, not so perfect. In the second example, would like the timer to keep a zero in front of the hours when ever it drops below 10. So the second example should display as: 05:35:10. Any help is greatly appreciated. Posted below is the modified code I'm using. Thanks! Code: <html> <head> <script type="text/javascript"> // really really simple to get the time from the server // this is for an ASP server: //var serverTime = <%= DateDiff("s",#1/1/1970#,Now())%>; // PHP Servers: var serverTime = <?php echo time(); ?>; // serverTime will hold the number of seconds since 1/1/1970 0:00:00 as it is on the server // we must adjust it to compensate for GMT offset // My server is on Pacific Daylight Time, so 7 hours offset: serverTime += 0 * 3600; // 7 hours, 3600 seconds per hour // NOTE: This adjustment MAY NOT be needed for PHP servers...I dunno. // // so calculate how far off the client is from the server: var now = new Date(); var clientTime = now.getTime(); // number of *milliseconds* since 1/1/1970 0:00:00 on client serverTime *= 1000; // convert server time to milliseconds, as well // the client and server disagree by this much: var clockOff = serverTime - clientTime; // could well be negative! // hopefully you can see, from basic algebra, that // serverTime = clientTime + clockOff // we want target to be 0:00:00 of next day var target = new Date( serverTime ); // serverTime in JS form // so bump the day by one and leave time as 0,0,0: target = new Date( target.getFullYear(), target.getMonth(), target.getDate() + 1 ); // and now ready for our timer countdown: var ticker = null; // the interval timer function countdown( ) { var clientNow = ( new Date() ).getTime(); var serverNow = clientNow + clockOff; // see? this is where we use that offset! var millisLeft = target.getTime() - serverNow; // milliseconds until server target time var secsLeft = Math.round( millisLeft / 1000 ); var timeLeft; var timeLeftWords; if ( secsLeft <= 0 ) { timeLeftWords = "Expired!"; timeLeft = "0 days 00:00:00"; clearInterval( ticker ); } else { var secs = secsLeft % 60; var minsLeft = Math.floor( secsLeft / 60 ); var mins = minsLeft % 60; var hrsLeft = Math.floor( minsLeft / 60 ); var hrs = hrsLeft % 24; var days = Math.floor( hrsLeft / 24 ); timeLeftWords = days + " days, " + hrs + " hours, " + mins + " minutes, " + secs + " seconds"; timeLeft = + (hrs < 10 ? "0" : "" ) + hrs + ":" + (mins < 10 ? "0" : "" ) + mins + ":" + (secs < 10 ? "0" : "" ) + secs; } document.getElementById("ticktock").innerHTML = timeLeft; } function startup( ) { countdown(); // first time setInterval( countdown, 1000 ); // then once a second } </script> </head> <body onload="startup()"> Time: <span id="ticktock"></span><br/> </body> </html> Hi, I thought this would be relatively simple, but it's more complicated than I thought, and I can't seem to find the question resolved anywhere. My problem is that on my site I sometimes have promotions that will end at midnight. I have to physically change the code at midnight to remove the promotional material. How would one go about using Javascript to only display a <div> during a certain time? Like "Use coupon code 123 to get free shipping! Good until midnight!" and set it to stop displaying that content at 12:00 AM. Then I could remove it the next day. Or the opposite, and have it take effect a midnight, etc. I'm sure it's been done before, right? Hi There, I am attempting to do a site which is of a similar format to a TV listings website. Each day's schedule will be on a different HTM page (contained within an iFrame), and I would like it to display the current day's schedule on the appropriate day. I have searched the forum, but can't find anything exactly like this (maybe I'm searching for the wrong thing), so any answers greatly appreciated. Thanks, Roz helow to all im new here? iwant to ask on how to display the sum of the 20 numbers i allready get the everage but i want to display the sum together of the everage this my code.. <html> <body> <script type = "text/javascript"> var numtotal = parseInt(prompt("How many numbers do you want to sum up?","")); var total = 0; for (var i=0; i<numtotal; i++) { var ans = parseFloat(prompt ("Enter a number", "")); if ((isNaN(ans)) || (ans == "")) { alert ("You must enter a number!! "); i -- ; } else {total = total + ans/numtotal}; } alert (total); // the total </script> </body> </html> any body help me please? hey all, Am trying to display the div tag and its content by clicking it. the code below displays the whole source code when cliked on the div with id = softros. I want to make this script to display the div in view source format of the browser when clicked on any div. Thanks in advance, looking forward for your ideas Regards, Bala <html> <head> <script> function viewSource() { window.open('view-source:'+location.href); } </script> </head> <body> <div id="softros" onClick="viewSource();" style="border:1px red solid;"> <img src="images/rain_small.jpg" alt="rain_small" title="rain_small" /> </div> </body> </html> |