JavaScript - Trying To Avoid A Circular Equation In Js
Hi,
Im working on a project for my website where I would like to be able to change the value of a number by using js, and using getElemenById. For example: "The taxi fare is $25" "A hamburger is $4" In the above sentence I would like to be able to change the value of 25 & 4 by giving them an id and then using js to increase (or decrease) their value, to allow for future inflation, without having to go back and manually change every number on lots of pages (if for example in 1 years time a hamburger is worth $6 then the info above is outdated and should be changed). If i could use a variable such as "RateUSD = 1" I could increase "1" to say "1.05" and it would increase the value of all id='USD' by 5% onload rather than having to manually change it by typing. I so far have come up with the code below, but I think the reason it does not work is because I have created a circular equation - id='USD" is the start of the equation, but it is also in the equation itself, and it is the resulting answer, so effectively I have created "A = A*B", or in this case "25 = 25*1.1" Would appreciate if anybody has had some experince with this type of js and could point me in the right direction. I chose "id" as I would like to be able to have different currencies (with different id, such as 'EURO','GBP', etc) on the same pages and on multiple pages. I'll crack it eventually, I would just like to know if I'm heading in the right direction, or is there a better method that I could use? I found plenty of example for changing text with "innerHTML", but so far I haven't seen any for updating numbers onload by calculation, except for forms, etc, which are different. The code: Code: <html> <head> <script type="text/javascript"> function changeCurrency(){ var RateUSD = 1.1 var USD = document.getElementById('USD').value ="" var A = RateUSD var B = USD var C = ((RateUSD) * (USD)) document.getElementById('USD').innerHTML = C } </script> </head> <body onload="changeCurrency()"> <p>The Taxi fare is USD$ <b id='USD'>25</b></p> <p>A hamburger is USD$ <b id= 'USD'>4</b></p> </body> </html> I will later put the js in an external file with a link to it "...src="support-files/currencyChange.js" (or something like that), but for now I have put it on the same page. Thanks and regards, Terry Similar TutorialsI am having some trouble trying to fix my math equation to calculate the total rent by aquiring values from my form fields. Converting the date fields to days and finding the number of days via two date fields is mainly where I am having trouble. Also, I am trying to have a window pop up before submission but the onclick event does not seem to function properly. Any suggestions would be greatly appreciated. Thank you. Below is the math equation I have come up with: Code: //calculate days from date field function calcTotal(date1, date2) { //assign variables var equip = parseFloat(document.forms[0].equipment.value) var pDate = parseFloat(document.forms[0].pickupDate.value) var pHours = parseFloat(document.forms[0].pickupHours.value) var pMinutes = parseFloat(document.forms[0].pickupMinutes.value) var rDate = parseFloat(document.forms[0].returnDate.value) var rHours = parseFloat(document.forms[0].returnHours.value) var rMinutes = parseFloat(document.forms[0].returnMinutes.value) // The number of milliseconds in one day var ONE_DAY = 1000 * 60 * 60 * 24 // Convert both dates to milliseconds var date1_ms = rDate.getTime() var date2_ms = pDate.getTime() // Calculate the difference in milliseconds var difference_ms = Math.abs(date1_ms - date2_ms) //calculate total cost and diplay in window.confirm() dialog box var pTime = pHours + pMinutes; var rTime = rHours + rMinutes; var total = (((difference_ms/ONE_DAY) - 1) * 24) * equip + ((rTime + (24 - pTime)) * equip); var OK = window.confirm(" The total rental cost is $" + total + "\n Click OK to accept, Cancel to decline"); if (OK) {return true} else {return false} } Below is the body section of the form: Code: <input type = "submit" name = "submit" value = "Submit Reservation" onclick = "calcTotal()"/> So I need to make a circular image map with a rollover state. I have circular buttons that I'm trying to put on my website, which I would like to not only look circular bu to BE circular. Because it just looks lame to hover over a square area and activate a button that's still 30 pixels away. I was digging through the Internets and found this: http://jsfiddle.net/7JJUk/ My idea was to tweak the rollover overlay into being as large as my original image and use the rollover image as the content of the overlay div. After loads of messing around, I finally have come to this: http://jsfiddle.net/7JJUk/248/ I just know i'm on to something, but I don't know anything, really, about Javascript. I've been messing with the tidbits to figure out what controls what, but the issue I can't get past is how the image will flicker like mad (every other pixel in Chrome, sporadically in Firefox 4 whether you move the mouse or not, and only as you pass through it at certain speeds in IE 9) as you hover over it. I have no idea if this is even possible, but if it is, please help me out. If there's a better way to be doing this altogether (without flash), I would absolutely love that. Especially if there's a way to use an image map with the position command in CSS.. Thanks!!! Hi, I have a scenario in which i have to drag and drop some objects in a circular motion, but under spacific boundaries. To expain the scenario better, I have attached a image of the problem. If possible kindly provide me code, either logical description/solution of the problem would be very helpful. Thanks Sa9chit I have a need to use a lot of pop ups to provide greater detail into items users are interested in. The problem is the percentage of time that a browser will block these pop ups. I would need to find a way to do one or both of two things: 1.) Find a way to show pop ups like with lightbox that will not be blocked by browsers without greatly hindering page load time 2.) Provide a Javascript / JQuery alert that can detect when a pop up has been blocked by a browser and notify a user through an alert along with a custom message written by me Anyone familiar with some Javascript coding that will do this or if lightbox is a practical solution without hindering page load time. There is likely to be anywhere from 10-30 different pop ups on a given page. Internet Explorer requires the user to click on an applet to activate it, which means two clicks if there is a start button, for example. I previously learned a workaround, which is to activate the applet from an external Javascript, something like this: Code: document.write('<applet code="' + appletname + '" width="' + w + '" height="' + h + '"></applet>'); This doesn't work in IE8. Is there a workaround for IE8? Thanks. i dont want to show the confirm message when using window.onbeforeunload. Please suggest a solution to hide the confirm message.. Hello, I'm writing a very simple code. Basically, there will be an array of strings from which one is randomly chosen and written to an element on the page. Here is a simplified version of how I'm executing it: Code: <html> <head> <script type="text/javascript"> function dyk() { document.getElementById('test').innerHTML = "foobar"; } </script> </head> <body onLoad="dyk();"> <div id="test">Hello<br /> </div> </body> </html> My only concern is the "Active Content" warning that comes up in IE. The clientele (mostly older people) are probably going to be IE users and many of them might be so untrusting of computers that they'll take the warning as a legitimate concern. Is there another way to write this simple code to avoid the warning? Thanks, Chris [Edit: I realize that the end user could disable such a warning, but I'm more wondering if there's a way to develop around it. Also, if it makes any difference, I've been viewing my page off of my computer, rather than from some source on the internet. Would uploading it to view it change whether the warning appears?] |