JavaScript - Javascript To Calculate Time Visit Between Current And Previous.
Hi everyone.
New to javascript here.... I have a problem here. I know how to store a cookie and check a cookie... but i don't know how to calculate the time between current visit and previous visit... Example. I logged in @ 1pm and logged in again @ 3pm... It should a msg like "your last visit was 2 hours ago" Can any one enlighten me ? Thank you! Similar TutorialsHi guys. I'm trying to make a small bit of scripting that will show the current time, updating once every second. What I need is the following: 1. Multiple timezones or GMT offsets (just put me on the right path, I can code them in, 2. Daylight savings time taken into consideration (only for Australia), adding the 1 hour during the times it is needed, 3. Text to show "Open" and "Closed" during different times (open during 8am to 5pm and closed if not 8am to 5pm.) I have the following code as a start, but I am completely stuck with how to get the rest of what I need! Any help would be appreciated. <h4>Victoria <script type="text/javascript"> <!-- var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() if (minutes < 10){ minutes = "0" + minutes } document.write(hours + ":" + minutes + " ") if(hours > 11){ document.write("PM") } else { document.write("AM") } //--> </script> <script type="text/javascript"> <!-- var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes() if (minutes < 10){ minutes = "0" + minutes } if(hours > 11){ document.write("True") } else { document.write("False") } //--> </script> </h4> Cheers in advance. Dale. I was trying to display time of last visit along with login name.. can someone help me on this pls? Hi! First post here! Would really appreciate some help on a javascript that would display the time elapsed since a particular visitor last visited my webpage, using cookies. So basically it should show something like: "You last visited my page 2 days & 12 mins ago!" I've a little background in java but none in javascript... Thanks so much! 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 Please can u help? how would i get the total work hours between two times (8:30 to 5:30) from a web form. I tried just minusing one from the orther but it came back with "Nan" Hello all, I am currently working on a site for a friend and have reached a navigational problem I cannot figure out how to achieve... He has a list of products that link to relevant individual pages which also have next and previous buttons to browse all the product pages on the site (only 10 so no big deal). However, he wants to add additional lists that recommend products by category preference? So for example; 4 products may appeal to a particular category, but when you click the link to view one of the products shown the next and previous buttons scroll through the entire products pages! and not only the ones recommended?? IS it possible using Javascript to define which pages are linked to as next previous without having to create lots more html copies of content pages? I have a basic knowledge of Javascript but cannot find a workable answer or example using google. Any help would be much appreciated. Thanks in advance... I tried to use the script to return the user to the previous page by clicking the link, and it did work, however, it would return me to the previous website I visited and not just the previous page within my site. Is there a way to override it by changing the code or is the code definitive? This was the code I had tried to use: Code: <a href="javascript:history.go(-1)">Back</a> I have a menu that lists all the categories and sub categories, when someone clicks a main category it opens up the sub cats for it. if someone clicks one of the sub cats the page open up to show all items in that category. But what I would like to find out is how do I get the menu to open up as it was so it shows the category and sub category open? Code: <!-- start show cat list --> <br><div style="font-weight: bold; font-size: 0.825em; padding: 0em 0em 0.3125em;">Select items by category</div> <ul class="catMenuItem"> <li><a style="background-image: url("images/triangle_down.gif");" href="#" class="titleTriangle"><span>cat1</span></a></li> <li style="display: block;" class="catSubMenu"> <a href="?cat=2">sub 1-2</a> (0)<br> <a href="?cat=7">sub 1-3</a> (2)<br> <a href="?cat=8">sub 1-4</a> (0)<br> <a href="?cat=9">sub 1-5</a> (0)<br> <br> </li> </ul> <ul class="catMenuItem"> <li><a href="#" class="titleTriangle"><span>cat2</span></a></li> <li style="display: none;" class="catSubMenu"> <a href="?cat=3">sub 2-1</a> (0)<br> <a href="?cat=4">sub 2-2</a> (0)<br> <a href="?cat=5">sub 2-3</a> (0)<br> <a href="?cat=6">sub 2-4</a> (1)<br> <br> </li> </ul> <ul class="catMenuItem"> <li><a href="#" class="titleTriangle"><span>cat3</span></a></li> <li style="display: none;" class="catSubMenu"> <br> </li> </ul> <ul class="catMenuItem"> <li><a href="#" class="titleTriangle"><span>cat4</span></a></li> <li style="display: none;" class="catSubMenu"> <br> </li> </ul> <ul class="catMenuItem"> <li><a href="#" class="titleTriangle"><span>cat5</span></a></li> <li style="display: none;" class="catSubMenu"> <br> </li> </ul> <script type="text/javascript"><!-- /* Categories Menu START */ var prevCat; function menu(newCat) { var mens; var anchors; if (prevCat) { mens = prevCat.parentNode.getElementsByTagName('li')[0]; anchors = mens.getElementsByTagName('a')[0].style.backgroundImage='url(images/triangle_right.gif)'; prevCat.style.display = 'none'; } if (newCat != prevCat) { mens = newCat.parentNode.getElementsByTagName('li')[0]; anchors = mens.getElementsByTagName('a')[0].style.backgroundImage='url(images/triangle_down.gif)'; newCat.style.display = 'block'; prevCat = newCat; } else { prevCat = null; } } onload = function() { var menus = document.getElementsByTagName('ul'); for (var a=0,x=menus.length; a<x; a++) { if (menus[a].className === 'catMenuItem') { menus[a].getElementsByTagName('li')[0].getElementsByTagName('a')[0].onclick = function() { menu(this.parentNode.parentNode.getElementsByTagName('li')[1]); } menus[a].getElementsByTagName('li')[1].style.display = 'none'; } } } /* Categories Menu END */ --></script> <!-- end show cat list --> 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 I am working on a form that has 15 rows for order entry. These rows are called: qty | part | desc | cost | amount I have the following ASP code that generates the rows: Code: <% For i = 1 To 15 %> <TR align=center><td><input type="text" NAME="qty<%Response.Write i%>" onChange='DoMath()'></td> <TD><INPUT TYPE="text" NAME="part<% Response.Write i %>"></TD> <TD><INPUT TYPE="text" NAME="desc<%Response.Write i %>"></TD> <TD><INPUT TYPE="text" NAME="cost<%Response.Write i%>" onChange="DoMath()"></TD> <TD><INPUT TYPE="text" NAME="amount<%Response.Write i%>" readonly></TD></TR> <% Next %> This gives me the following fields in the form: qty1 | part1 | desc1 | cost1 | amount1 qty2 | part2 | desc2 | cost2 | amount2 etc. My Javascript (DoMath) to calculate the row totals looks like this for now: Code: <script type='text/javascript'> function DoMath(){ var Units = document.PlaceOrder.qty1.value; var Rate = document.PlaceOrder.cost1.value; var Total = Units * Rate; document.PlaceOrder.amount1.value = Total.toFixed(2); document.PlaceOrder.grandtotal.value = Total.toFixed(2); } </script> This works fine for the first row, but I need it to scale for the rest of the rows, and also allow for future addition/expansion. Unfortunately, I am Javascript-tarded and can't figure it out, despite numerous examples online... I also need to find a way to recalculate the "grandtotal" box on the form based on whether or not the checkbox called "taxChecked" is checked. If the user checks it, I need it to recalculate the "grandtotal" field with a tax rate, and if they un-check it, it should recalcuate "grandtotal" WITHOUT the tax rate. Any suggestions or pointers are greatly appreciated! Can anyone help me with the following Javascript. I am going crazy trying to figure this out because it should be easy. Basically I want to calculate the percentage of a number, but I'm getting a really weird result. In the following code f is equal to 3 and x.length is equal to 8. The part that isn't working is emphasised in bold. Basically 3/8 * 100 should result in 37.5 but the result I am getting with the following code is 7934570.3125. How do you calculate this percentage in Javascript? Code: function displaymember() { var m = 1; var f = 1; for(i=0;i<x.length;i++) { sex=(x[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue); if (sex=="Male") { m++; } else { f++; } percent=f/x.length * 100 document.getElementById("fixed").innerHTML=percent; } } Hi, I need a help with a project I am working on. I am not a developer so not so familiar with javascript. Suppose I have a map with ten junctions and based on that map, I need to calculate all the possible routes between one junction to another. How do I represent the map in javascript and how do I code the function to calculate all the possible routes?? :-( many thanks if someone can help me It's been a long time since I've messed around with Javascript. I had some resources and books that sort of showed what I was wanting to do. Essentially what I am trying to create is a calculator which allows the user to check the components of their computer and when they hit "calculate" it will output the price of the system for them. I found some simplified examples of what I am trying to do online, but I cannot for the life of me figure out why when I hit "calculate" nothing happens The code is below (I pasted the wholes of both codes because I'm not sure where exactly the problems are). Any help is definitely appreciated! html code: Code: <html> <head> <script language="JavaScript1.1" src="calculate.js" type="text/javascript"></script> </head> <body onLoad="load ()"> <center> <form name="calc" method="POST"> <table width="100%" border="0" cellpadding="3"> <tr> <td colspan="11"><center><h1>Computer Pricing Calculator</h1></center></td> </tr> <tr> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">TYPE</font></th> <td width="5"></td> <th bgcolor="#000000" colspan="5" align="center"><font color="white" size="+2">PROCESSOR</font></th> <td width="5"></td> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">HARD DRIVE</font></th> </tr> <!--Row 1 --> <tr> <td colspan="2"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Single Core Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="single" size="10"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> </tr> <!--Row 2 --> <tr> <td colspan="2"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Dual Core Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="double" size="10"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> </tr> <!--Row 3 --> <tr> <td bgcolor="#eeeeee" width="20%">Desktop/Tower</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="pc" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Core i-3 Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="triple" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Hyper-threaded Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ht" size="10"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> </tr> <!--Row 4 --> <tr> <td colspan="2"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Quad Core Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="quad" size="10"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Enter the size (gb)</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="text" name="size" size="1"></td> <td width="5"></td> </tr> <!--Row 5 --> <tr> <td bgcolor="#eeeeee" width="20%">Laptop</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="laptop" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Core i-5 Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="five" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Enter the speed (ghz)</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="text" name="speed" size="1"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> </tr> <!--Row 6 --> <tr> <td colspan="2"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Six Core Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="six" size="10"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> </tr> <!--Row 7 --> <tr> <td colspan="2"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Core i-7 Processor</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="seven" size="10"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> <td colspan="2"></td> <td width="5"></td> </tr> <tr> <td height="25"> </td> </tr> <!--Row 1 --> <tr> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">RAM</font></th> <td width="5"></td> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">VIDEO CARD</font></th> <td width="5"></td> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">OPTICAL DRIVE</font></th> <td width="5"></td> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">OFFICE</font></th> </tr> <!--Row 2 --> <tr> <td bgcolor="#eeeeee" width="20%">512 MB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram512mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">No Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="novid" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">CD/ROM Only</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="cdrom" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Open Office</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="nooffice" size="10"></td> </tr> <!--Row 3 --> <tr> <td bgcolor="#eeeeee" width="20%">768 MB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram768mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">64 MB Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vid64mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">CD/RW Only</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="cdrw" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Office 97</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="office97" size="10"></td> </tr> <!--Row 4 --> <tr> <td bgcolor="#eeeeee" width="20%">1.0 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram1000mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">128 MB Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vid128mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">CD/RW - DVD/ROM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="cdrwdvdrom" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Office 2003</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="office03" size="10"></td> </tr> <!--Row 5 --> <tr> <td bgcolor="#eeeeee" width="20%">1.5 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram1500mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">256 MB Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vid256mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">CD/RW - DVD/RW</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="cdrwdvdrw" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Office 2007</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="office07" size="10"></td> </tr> <!--Row 6 --> <tr> <td bgcolor="#eeeeee" width="20%">2.0 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram2000mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">512 MB DDR Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vid512mb" size="10"></td> <td width="5"></td> <td width="20%"></td> <td align="center" width="4%"></td> <td width="5"></td> <td width="20%"></td> <td align="center" width="4%"></td> </tr> <!--Row 7 --> <tr> <td bgcolor="#eeeeee" width="20%">2.5 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram2500mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">768 MB Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vid768mb" size="10"></td> <td width="5"></td> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">CONNECTIVITY</font></th> <td width="5"></td> <th bgcolor="#000000" colspan="2" align="center"><font color="white" size="+2">OS</font></th> </tr> <!--Row 8 --> <tr> <td bgcolor="#eeeeee" width="20%">3.0 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram3000mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">1.0 GB Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vid1000mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">NIC</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="nic" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Windows XP</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="xp" size="10"></td> </tr> <!--Row 9 --> <tr> <td bgcolor="#eeeeee" width="20%">3.5 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram3500mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">DDR2/DDR3 Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ddr23vid" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Modem</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="modem" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Windows Vista</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="vista" size="10"></td> </tr> <!--Row 10 --> <tr> <td bgcolor="#eeeeee" width="20%">4.0 GB RAM</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ram4000mb" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">DDR5 Video Card</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="ddr5vid" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Wireless</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="wireless" size="10"></td> <td width="5"></td> <td bgcolor="#eeeeee" width="20%">Windows 7</td> <td bgcolor="#eeeeee" align="center" width="4%"><input type="checkbox" name="windows7os" size="10"></td> </tr> <tr> <td height="40"> </td> </tr> <tr> <td colspan="3"></td> <td colspan="2" align="center"><input name="Submit" type="submit" style="background-color:#ffff00; color:#000000; border:5px solid #000000; font-family:arial; font-size:15pt; font-weight:900; letter-spacing=2px" onClick="count ()" value="CALCULATE PRICE!"></td> <td width="5"></td> <td colspan="2" align="center"><input type="reset" value="RESET VALUES!" style="background-color:#ffff00; color:#000000; border:5px solid #000000; font-family:arial; font-size:16pt; font-weight:900; letter-spacing=2px"></td> <td colspan="3"></td> </tr> <tr> <td height="40"> </td> </tr> <tr> <td bgcolor="#ffffff" colspan="11" align="center"><font size="18">PRICE = $</font><input name="pay" type="text" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:25pt; letter-spacing=1px" size="10"></td> </tr> </table> </form> </center> </body> </html> javascript code (calculate.js) Code: function load() { window.status = "Pricing Guide" } function count() { //Type variables var pcprice = 0; var laptopprice = 20; var typeprice = 0; //Processor variables var singleprice = 1.67; var doubleprice = 2.05; var tripleprice = 1.31; var quadprice = 2.30; var fiveprice = 1.97; var sixprice = 2.0; var sevenprice = 3.09; var htprice = 0; var processorprice = 0; //RAM variables var ram512mbprice = 15; var ram756mbprice = 22; var ram1000mbprice = 30; var ram1500mbprice = 45; var ram2000mbprice = 60; var ram2500mbprice = 75; var ram3000mbprice = 80; var ram3500mbprice = 95; var ram4000mbprice = 110; var ramprice = 0; //Video Card variables var novidprice = 0; var vid64mbprice = 10; var vid128mbprice = 15; var vid256mbprice = 20; var vid512mbprice = 28; var vid768mbprice = 33; var vid1000mbprice = 40; var ddr23vidprice = 1.5; var ddr5vidprice = 2; var vidprice = 0; var videoprice = 0; //Optical Drives variables var cdromprice = 2; var cdrwprice = 5; var cdrwdvdromprice = 20; var cdrwdvdrwprice = 35; var driveprice = 0; //Connectivity variables var nicprice = 0; var modemprice = 5; var wireless price = 20; var connectprice = 0; //Office variables var noofficeprice = 0; var office97price = 0; var office03price = 30; var office07price = 50; var officeprice = 0; //Operating System variables var xpprice = 0; var vistaprice = 0; var windows7osprice = 110; var osprice = 0; //Hard drive - Input Box var hdsize = document.getElementById('size'); var hdprice = 0; //Processor Speed - Input Box var pcspeed = document.getElementById('speed'); var processorprice = 0; //COMPUTER TYPE - Check Boxes if (calc.pc.checked){ var typeprice = document.calc.pc.value = pcprice; } if (calc.laptop.checked){ var typeprice = document.calc.laptop.value = laptopprice; } //Hard Drive var hdprice = hdsize * 0.30; //Processor - Check Boxes if (calc.single.checked){ var processorprice = document.calc.single.value = singleprice * pcspeed; } if (calc.double.checked){ var processorprice = document.calc.double.value = doubleprice * pcspeed; } if (calc.triple.checked){ var processorprice = document.calc.triple.value = tripleprice * pcspeed; } if (calc.quad.checked){ var processorprice = document.calc.quad.value = quadprice * pcspeed; } if (calc.five.checked){ var processorprice = document.calc.five.value = fiveprice * pcspeed; } if (calc.six.checked){ var processorprice = document.calc.six.value = sixprice * pcspeed; } if (calc.seven.checked){ var processorprice = document.calc.seven.value = sevenprice * pcspeed; } if (calc.ht.checked){ var htprice = document.calc.ht.value = 10; } //RAM - Check Boxes if (calc.ram512mb.checked){ var ramprice = document.calc.ram512mb.value = ram512mbprice; } if (calc.ram756mb.checked){ var ramprice = document.calc.ram756mb.value = ram756mbprice; } if (calc.ram1000mb.checked){ var ramprice = document.calc.ram1000mb.value = ram1000mbprice; } if (calc.ram1500mb.checked){ var ramprice = document.calc.ram1500mb.value = ram1500mbprice; } if (calc.ram2000mb.checked){ var ramprice = document.calc.ram2000mb.value = ram2000mbprice; } if (calc.ram2500mb.checked){ var ramprice = document.calc.ram2500mb.value = ram2500mbprice; } if (calc.ram3000mb.checked){ var ramprice = document.calc.ram3000mb.value = ram3000mbprice; } if (calc.ram3500mb.checked){ var ramprice = document.calc.ram3500mb.value = ram3500mbprice; } if (calc.ram4000mb.checked){ var ramprice = document.calc.ram4000mb.value = ram4000mbprice; } //VIDEO CARD - Check Boxes if (calc.novidprice.checked){ var vidprice = document.calc.novidprice.value = novidprice; } if (calc.vid64mb.checked){ var vidprice = document.calc.vid64mb.value = vid64mbprice; } if (calc.vid128mb.checked){ var vidprice = document.calc.vid128mb.value = vid128mbprice; } if (calc.vid256mb.checked){ var vidprice = document.calc.vid256mb.value = vid256mbprice; } if (calc.vid512mb.checked){ var vidprice = document.calc.vid512mb.value = vid512mbprice; } if (calc.vid768mb.checked){ var vidprice = document.calc.vid768mb.value = vid768mbprice; } if (calc.vid1000mb.checked){ var vidprice = document.calc.vid1000mb.value = vid1000mbprice; } var videoprice = vidprice; if (calc.ddr23vid.checked){ var videoprice = document.calc.ddr23vid.value = vidprice * 1.5; } if (calc.ddr5mb.checked){ var videoprice = document.calc.ddr5mb.value = vidprice * 2; } //OPTICAL DRIVES - Checkbox if (calc.cdrom.checked){ var driveprice = document.calc.cdrom.value = cdromprice; } if (calc.cdrw.checked){ var driveprice = document.calc.cdrw.value = cdrwprice; } if (calc.cdrwdvdrom.checked){ var driveprice = document.calc.cdrwdvdrom.value = cdrwdvdromprice; } if (calc.cdrwdvdrw.checked){ var driveprice = document.calc.cdrwdvdrw.value = cdrwdvdrwprice; } //CONNECTIVITY - Checkbox if (calc.nic.checked){ var connectprice = document.calc.nic.value = nicprice; } if (calc.modem.checked){ var connectprice = document.calc.modem.value = modemprice; } if (calc.wireless.checked){ var connectprice = document.calc.wireless.value = wirelessprice; } // OFFICE - Checkbox if (calc.noffice.checked){ var officeprice = document.calc.nooffice.value = officeprice; } if (calc.office97.checked){ var officeprice = document.calc.office97.value = office97price; } if (calc.office03.checked){ var officeprice = document.calc.office03.value = office03price; } if (calc.office07.checked){ var officeprice = document.calc.office07.value = office07price; } //OPERATING SYSTEM - Checkbox if (calc.xp.checked){ var osprice = document.calc.xp.value = xpprice; } if (calc.vista.checked){ var osprice = document.calc.vista.value = vistaprice; } if (calc.windows7os.checked){ var osprice = document.calc.windows7os.value = windows7osprice; } document.calc.pay.value = typeprice + processorprice + htprice + ramprice + videoprice + driveprice + connectprice + officeprice + osprice + hdprice; } Hi everyone, I am pretty new to JS and I am looking for help writing a function that will dynamically calculate filed values. I have a PHP-generated form which may have a varying number of fields. I need to: 1. calculate the line total for each row -- unitprice * units = linetotal 2. calculate total of all linetotals. I have named my fields as follows: unitprice[1], unitprice[2]... , units[1], units[2], ... I have the following calculate function: Code: function calculateOld() { // get both values unitprice = document.forms["invoice"].unitprice.value; units = document.forms["invoice"].units.value; // do some calculation lineTotal = formatNumber((unitprice * units), 2); // set the value in the right field document.forms["invoice"].linetotal.value = lineTotal; unitprice2 = document.forms["invoice"].unitprice2.value; units2 = document.forms["invoice"].units2.value; if(unitprice2 != '') { // do some calculation lineTotal2 = formatNumber((unitprice2 * units2), 2); // set the value in the right field document.forms["invoice"].linetotal2.value = lineTotal2; document.forms["invoice"].totalprice.value = formatNumber((parseFloat(lineTotal) + parseFloat(lineTotal2)),2); } else { document.forms["invoice"].linetotal2.value = ''; document.forms["invoice"].totalprice.value = formatNumber(lineTotal,2); } } This does calculate what I need but only if I have up to two rows. I need to make the function dynamically count how many rows there are, and calculate the linetotal for each row. And here's where my limited JS knowledge brings me to a halt. I have been thinking about what this new and dynamic function should look like, but that's the best I could produce... Code: function calculate() { var unitprice[i] = document.forms["invoice"].unitprice[i].value; var units[i] = document.forms["invoice"].units[i].value; var linetotal[i] = formatNumber((unitprice[i] * units[i]), 2); return linetotal; } Your help will be appreciated. Please explain how things are done, don't just give me the code. Thanks in advance! Need help please asap. It might be simple but i couldn't work out the script. help! ---------------- Formfield.anzahl1 = number entered by customer Formfield.Price1 = Ergebnisfeld1 e.g. Anzahl1= 1 Price = 270 *if Anzahl1 = 2 then Price = 270*2 I need to do this for two form option. 2nd field would be as follows Formfield.Anzahl2= number entered by customer Formfield.Price2 = Ergebnisfeld2 Then Formfield.Total = Ergebnisfeld1 + Ergebnisfeld2 ------------------- How can I convert these above to javascript? Hi Guys, I want to output my pagetitle in javascript. An idea of syntax? <title> products</title> eg My page title is javascript code outputs... My page title is products no joy with Code: <body> <script TYPE="text/javascript"> document.write(document.title); </script> </body> Thanks |