JavaScript - How To Find Round Trip Time Of A Request
I was wondering if there is a way to find the total round trip time of a request. Addins like firebug and chromes console show you this round trip time but i was hoping there was a way to extract it from the response itself.
I would also like to know the response time from when the server sent the request and the client received it. I do not think this is possible since the server and client have different timing systems but it would be very useful. Similar TutorialsHi, I am trying to make a fuinction that, when called, will return the string that is retrned in text form from my php code. This is what i currently have, but it is just failing when it is run, what am i doing wrong? Code: function shortenUrl(url) { var response; var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "http://10.1.1.10/projects/short/?ext&url=" + encodeURIComponent(url), false); xmlhttp.send(null); xmlhttp.onload = function() { var response = xmlhttp.responseText; return response; } return "Failed!"; } alert(shortenUrl("http://www.google.com.au/")); Thanks Edit: ohh, and this is running chrome, so no standards issues Hi i want to find out the idle time when there is no http request is going on... i dont want to track any mouse or key board events... i dont want that... i read these thread but it is only about screen idle time http://www.codingforums.com/showthre...t=33068&page=2 i am trying to track the time when there is no transaction going between client and server and no http request is sending . if i will get that time then that time i can use to load my additional javascript files... so further transaction of user will become speed up.... i appreciate your help THANKS ok, i'm sure you all will laugh at this, but it seems really bizzario to me. i have two small routines worked out. routine G gets a value out of the db and brings it back to the browser script. routine P puts a value into the db from the browser script. they both run fine. but......... you have to turn the browser totally off and restart it after retrieving a value out of the db (?) why? is this some kind of "clear memory" i need to be doing. its like the last value i retrieved thru the server is stuck in memory and keeps coming up, and it won't flush out until i turn the browser off and restart it. is this a Javascript problem or a PHP problem? i dont' have a clue, maybe i need to somehow flush the memory in the PHP file after i echo() back the result.? is that normal? thanks, Paul Just started to learn java & came up with the following, but can't get the math.round to work. Anyone able to tell me where I'm going wrong please ??? <p> <script type="text/javascript">// <![CDATA[ var metrics = { "mm" : 1, "cm" : 10, "m" : 1000, "inch" : 25.4, "foot" : 304.8 }; function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.roundform.numberfield.value = parseFloat(newnumber); // Output the result to the form field (change for your purposes) } function roundme(len, wid, sq){ math.round.len; wid = math.round(wid); sq = math.round(sq); alert(len); }; function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.roundform.numberfield.value = parseFloat(newnumber); // Output the result to the form field (change for your purposes) }; function changeme(id, action) { var val = document.getElementById("sizegroup"); if (val.style.display == 'none') { val.style.display = 'block' } else { val.style.display = 'none' } }; function convert(num, dec){ var val = document.getElementById("boxa").value; var val2 = document.getElementById("boxb").value; if(isNaN(val)){return val}; if(isNaN(val2)){return val2}; document.getElementById("boxc").value = val * metrics[document.getElementById("choice1").value]/ metrics[document.getElementById("choice3").value]; metrics[document.getElementById("choice1").value]/ metrics[document.getElementById("choice3").value]; document.getElementById("boxd").value = val2 * metrics[document.getElementById("choice2").value]/ metrics[document.getElementById("choice4").value]; document.getElementById("sqmtrs").value = document.getElementById("boxc").value * document.getElementById("boxd").value ; document.getElementById("boxc").value = math.round(document.getElementById("boxc").value); }; var interval = null; function watchChanges(){ interval == null ? setInterval("convert()", 500) : clearInterval(interval); } // ]]></script> </p> <p>Length in imperial-metric / Width in imperial-metric</p> <div><input id="boxa" style="width: 40px;" onfocus="watchChanges()" onblur="watchChanges()" type="text" /><select id="choice1" onchange="convert();"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option value="m">metres</option> <option selected="selected" value="foot">feet</option> <option value="inch">inches</option> </select> <input id="boxb" style="width: 40px;" onfocus="watchChanges()" onblur="watchChanges()" type="text" /><select id="choice2" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option value="m">metres</option> <option selected="selected" value="foot">feet</option> <option value="inch">inches</option> </select></div> <div><input id="boxc" style="width: 40px;" type="text" disabled="disabled" /><select id="choice3" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option selected="selected" value="m">metres</option> <option value="foot">feet</option> <option value="inch">inches</option> </select> <input id="boxd" style="width: 40px;" type="text" disabled="disabled" /><select id="choice4" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option selected="selected" value="m">metres</option> <option value="foot">feet</option> <option value="inch">inches</option> </select></div> <p> </p> <div>Total sq metres : <input id="sqmtrs" style="width: 40px;" type="text" value="" disabled="disabled" /></div> <p> </p> <div class="label">Please round up to half a metre when choosing</div> <table border="0" cellspacing="0" cellpadding="5"> <tbody> <tr> <td>Round:</td> <td><input type="text" name="numberfield" value="" /> to <input type="text" name="decimalfield" value="2" size="3" /> decimal places</td> </tr> <tr> <td>Result:</td> <td><input type="text" name="roundedfield" value="" /> <input onclick="roundNumber(numberfield.value, decimalfield.value);" type="button" value="Calculate" /></td> </tr> </tbody> </table> Hey Guys, I'm working on a site and it needed borders with opacity, and since you can do it with CSS I done it With jQuery. But now I would like to round the corners of it, I did try border-radius, but it's only effecting the containing div not the borders(see below). Is there a solution to this? Here's the small snippet of JS: PHP Code: $('.mainContent').border({ width: 6, color: 'white', alpha: .4 }); Hi, First time user of Javascript and built an online calculator, trouble is I dont know where or how to code it so the answer ends with only 2 decimals I have embedded code, help appreciated. Personally I think it's a miracle the darn thing works. Link to page it's on. Any help appreciated, I have searched and read but after hours of trying stuff gave up. <!-- function treevalue() { document.volume.result.value=(((3.14159*((document.volume.radius.value)*(document.volume.radius.valu e)))*(document.volume.height.value))/3)*(document.volume.base.value)*(document.volume.e.value)*(document.volume.fv.value)*(document.volum e.l.value); } // --> Thanks Eric i had to create a function to calculate percentage and round to integer need 2 parameters of item and sum function will return value of item variable divide the sum by 100 and round to nearest integer using Math.round this is my code that i came up with Code: function calcPercent(item,sum){ // script element to calculate the percentage which is rounded to the nearest integer var items = Math.round( (item/sum)*100); // script element to get the percentage return items; } calcPercent(1, 3); Does this make sense? thanks Having trouble with the alert(Math.round coding. "r" is the results or final value, and I want to divide this result/final value by "f" I have alert(Math.round(r / f) + ' calories/day to burn); but I its coming up saying NaN calories/day to burn. How do I divide "f" into "r" correctly? Code: } function calculate() { var f = document.forms[0], g, w, f, h, a, l, r; for (var i=0; i<(f.length-1); i++) { if (f.elements[i].selectedIndex == 0) { alert('Sorry, all options must be selected.'); return false; } } g = f.g.options[f.g.selectedIndex].value; w = f.w.options[f.w.selectedIndex].value; h = f.h.options[f.h.selectedIndex].value; a = f.a.options[f.a.selectedIndex].value; l = f.l.options[f.l.selectedIndex].value; if (g == 'm') { r = ((66 + ((13.7 * w) / 2.2) + (5 * h * 2.54)) - (6.8 * a)) * l; } else { r = ((655 + ((9.6 * w) / 2.2) + (1.8 * h * 2.54)) - (4.7 * a)) * l; } alert(Math.round(r) + ' calories/day is what you require'); alert(Math.round(r / f) + ' calories/day to burn); return false; Hello: I have this js function: Code: <script type="text/javascript"> function updatesum() { document.PaymentForm.newbalance.value = (document.PaymentForm.balance.value -0) - (document.PaymentForm.paymentamount.value -0); } </script> I want to round the value of Code: document.PaymentForm.newbalance.value to two decimal points. May I request some assistance! i have a program where a user enters a temperature in farenheit and the program converts it to celcius. below is my code: Code: <html> <head> <title>JavaScript Assignment 4 Part 1</title> </head> <body> <h2>Welcome to the Temperature Calculator!!</h2> <script type="text/javascript"> var fTemp; var number1; var cTemp; fTemp = window.prompt( "Please enter temperature in Farenheit:", "0" ); number1 = parseInt( fTemp ); cTemp = (5/9) * (number1 - 32); document.writeln("The corresponding temperature in Celcius is: " + cTemp); </script> </body> </html> what i cant figure out is how to round off the temperature in celcius so that it doesnt display something like 26.666666666667 i tried putting math.round in "cTemp = (5/9) * (number1 - 32);" but when i do my program doesnt work any advice on how to go about doing this? thanks Hi, my javascript calculates a total figure. It rounds it up though and I want it to give me a decimal (x2) total. Please help. Here is my code so far: Code: <script type="text/javascript"> function calculateText() { var op1=document.getElementById('Age02'); var op2=document.getElementById('Girl35'); var op3=document.getElementById('Boy35'); var op4=document.getElementById('Girl610'); var op5=document.getElementById('Boy610'); var op6=document.getElementById('Age11'); var op7=document.getElementById('Guest'); var op8=document.getElementById('VIP'); var op9=document.getElementById('School'); var op10=document.getElementById('3DFilm'); var op11=document.getElementById('BFast'); var op12=document.getElementById('PNGift'); var op13=document.getElementById('PStand'); var op14=document.getElementById('PLrg'); var op15=document.getElementById('PReP'); var op16=document.getElementById('KyMg'); var op17=document.getElementById('SnwGlb'); var op18=document.getElementById('PBbl'); var op19=document.getElementById('USB'); var op20=document.getElementById('SantaL'); var op21=document.getElementById('SantaK'); var op22=document.getElementById('FreeP'); var op23=document.getElementById('PUpgrd'); var op24=document.getElementById('StaffP'); var op25=document.getElementById('CompEntry'); var op26=document.getElementById('241'); var op27=document.getElementById('50Percent'); var op28=document.getElementById('Voucher'); var result=document.getElementById('Total'); if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0; if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0; if(op3.value=="" || op3.value!=parseFloat(op3.value)) op3.value=0; if(op4.value=="" || op4.value!=parseFloat(op4.value)) op4.value=0; if(op5.value=="" || op5.value!=parseFloat(op5.value)) op5.value=0; if(op6.value=="" || op6.value!=parseFloat(op6.value)) op6.value=0; if(op7.value=="" || op7.value!=parseFloat(op7.value)) op7.value=0; if(op8.value=="" || op8.value!=parseFloat(op8.value)) op8.value=0; if(op9.value=="" || op9.value!=parseFloat(op9.value)) op9.value=0; if(op10.value=="" || op10.value!=parseFloat(op10.value)) op10.value=0; if(op11.value=="" || op11.value!=parseFloat(op11.value)) op11.value=0; if(op12.value=="" || op12.value!=parseFloat(op12.value)) op12.value=0; if(op13.value=="" || op13.value!=parseFloat(op13.value)) op13.value=0; if(op14.value=="" || op14.value!=parseFloat(op14.value)) op14.value=0; if(op15.value=="" || op15.value!=parseFloat(op15.value)) op15.value=0; if(op16.value=="" || op16.value!=parseFloat(op16.value)) op16.value=0; if(op17.value=="" || op17.value!=parseFloat(op17.value)) op17.value=0; if(op18.value=="" || op18.value!=parseFloat(op18.value)) op18.value=0; if(op19.value=="" || op19.value!=parseFloat(op19.value)) op19.value=0; if(op20.value=="" || op20.value!=parseFloat(op20.value)) op20.value=0; if(op21.value=="" || op21.value!=parseFloat(op21.value)) op21.value=0; if(op22.value=="" || op22.value!=parseFloat(op22.value)) op22.value=0; if(op23.value=="" || op23.value!=parseFloat(op23.value)) op23.value=0; if(op24.value=="" || op24.value!=parseFloat(op24.value)) op24.value=0; if(op25.value=="" || op25.value!=parseFloat(op25.value)) op25.value=0; if(op26.value=="" || op26.value!=parseFloat(op26.value)) op26.value=0; if(op27.value=="" || op27.value!=parseFloat(op27.value)) op27.value=0; if(op28.value=="" || op28.value!=parseFloat(op28.value)) op28.value=0; result.value=0; result.value=parseInt(result.value); result.value=parseInt(result.value)+parseInt(op1.value*5)+parseInt(op2.value*5)+parseInt(op3.value*5)+parseInt(op4.value*5)+parseInt(op5.value*5)+parseInt(op6.value*5)+parseInt(op7.value*0)+parseInt(op8.value*8.50)+parseInt(op9.value*3.75)+parseInt(op10.value*0)+parseInt(op11.value*10)+parseInt(op12.value*5)+parseInt(op13.value*3)+parseInt(op14.value*4)+parseInt(op15.value*2)+parseInt(op16.value*4)+parseInt(op17.value*5)+parseInt(op18.value*3)+parseInt(op19.value*5)+parseInt(op20.value*4)+parseInt(op21.value*3)+parseInt(op22.value*0)+parseInt(op23.value*1)+parseInt(op24.value*0)+parseInt(op25.value*0)+parseInt(op26.value*4)+parseInt(op27.value*2)-parseInt(op28.value); } </script> Hi Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } alert(err-str); here ind==1 is from_time and ind==2 is to_time,i need to validate time as to_time must be always greater than from-time,if condition fails an alert msg should populate.time format is[05:00]as it is in string format im unable to do the validation for it.(ex:from-time=08:00 to-time=07:59 condition fails) thank you. Hello im using dhtmlx grid in this cells i have from time and to time (i.e ind==1 and ind==2) i need to validate time where to-time must be greater than from-time else it should alert an message,i have writeen a normal Regular expression for the time validation.as the time is i string format i.e[05:00],please can any one send me code for that. Code: var err_str=""; function validate_grid(value,id,ind) { if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } hi im using dhtml xgrid where i need to do validation for time ,(from-time and to-time i.e ind==1 and ind==2 ) to-time must be greater than from-time else i need to alert a message to-time must be greater than from-time. can any one send me the code for it time format is[05:00]. Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } 1 down vote favorite I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: http://jsfiddle.net/BgEtE/ thank you for help hi, can some one help me how to get the time and date difference? given two time and date with the following format like in textbox A: 2011-05-03 17:35:47.0 and textbox B: 2011-05-03 16:35:47.0 then the output would be: 0 days, 1 hour, 0 minutes, 0 seconds regards, verve I'm not really a Java writer, so I don't know how to do this myself, though I imagine it would be pretty simple. I am looking to add a script to a webpage that allows users to input a time manually, and have it converted to GMT/Zulu time and display the converted time. I have seen a lot of time zone conversion scripts online, but they all just convert whatever the current system time is to another time zone. I am looking for a script that allows users to convert a time and show the zulu time, for times other than the current time. The time zone the inputed local time would be in is +4:30 (Kabul). I don't really care about style or aestehtics, just a simple script I can insert into a web page to have a time input field. The converted output time can appear in another field, a popup bubble, etc, again style isn't really an issue. It's really just to help people in my job who need to know what the GMT/Zulu time was for certain local times after the fact. One would think it shouldn't be that hard to just subtract 4:30 in your head, but apparently it is. Sorry if just asking for code outright like this is frowned upon. This is my first time doing JavaScript I don't what I did wrong here, but the problem its not showing up the current date and time. Code: <script language = "JavaScript" type="text/javascript"> now = new Date(); localtime = now.toString(); utctime = now.GMTString(); document.wite("<b>localtime</b>" + localtime + "</br>"); document.write("<b>utctime</b>" + utctime); </script> This is what supposed to look like I have tried using different browser chrome,IE9,Maxtor, and Opera my OS is Win7 Can someone modify the code below to save name & email to a file named logfile.dat please? Code: <html> <HEAD> <SCRIPT language="JavaScript"> function WriteFile(name, email) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var fh = fso.CreateTextFile("D:\\logfile.dat", true); fh.WriteLine(name); fh.WriteLine(email); fh.Close(); } function sendtopage(whatpage) { alert(whatpage) window.location.href =whatpage; return true; } redirectTime = "3000"; redirectURL = "http://www.cnn.com"; function timedRedirect() { alert('Thank you'); setTimeout("location.href = redirectURL;",redirectTime); } function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function checkEmailCookie() { var email=getCookie("email"); if (email!=null && email!="") { alert("Email: " + email); } } function checkNameCookie() { var name=getCookie("name"); if (name!=null && name!="") { alert("Name: " + name); } } </SCRIPT> <style type="text/css"> .Class01 { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 24px; font-weight: bold; } .Class02 { font-size: 36px; font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; } .Class013 { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; } .Class01 .Class013 .Class01 { font-weight: bold; } .Classzz { font-family: "Lucida Console", Monaco, monospace; } .Classxx { font-weight: bold; font-size: 24px; } .Classzz { font-family: "Lucida Console", Monaco, monospace; } .style1 { text-align: center; } </style> </HEAD> <body gcolor="#FFFFFF" background="../MCM-background.jpg"> <center> <p class="style1"><img src="../mcm_header2.gif" alt="Header" width="790" height="199"></p> </center> <p></p> <form name="fm" action="http://www.meadecountymessenger.com"> <div align="center"> <p> </p> <p><span class="Class01"><span class="Class02">Please enter the following.</span></span></p> <p> </p> <p><span class="Class01">Your Name: </span> <input name="name" type="text" size="60" /> </p> <p><span class="Classzz"><br /> <span class="Classxx">Your eMail:</span></span><span class="Class01"> </span> <input name="email" type="text" size="60" /> <script type="text/javascript"> setCookie("email",document.fm.email.value,365); setCookie("name",document.fm.name.value,365); </SCRIPT> </p> <p> <input name="" type="submit" class="Class01" OnClick="alert('Thank You !');" value="Submit"/> </p> </div> </form> </body> </html> |