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"
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:
<html>
<head>
<script type="text/javascript">
function changeCurrency(){
[Code].....
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.
var useWidth = "400px"; var speed = 250 // greater is slower;
var message = "Now is the time for all good men to come to the aid of their country. That's one small step for man, one giant leap for mankind. Ask not what your country can do for you, ask what you can do for your country. | ";
// Remember to include the vertical bar | at the end of the message(s);
var mContainer = ""; var circleMsg = ""; var prevMsg = ""; var useFloat = ""; var xV = 0; var xL = 0; var msgLength = 0;
function updateMessage(){
if (circleMsg == ""){circleMsg = mContainer.lastChild.data} else {circleMsg = prevMsg} var separatorIdx = circleMsg.lastIndexOf('|'); if (separatorIdx == -1){separatorIdx = msgLength} circleMsg = circleMsg.substring(1,separatorIdx); var spliceStr = message.substring(0,msgLength-separatorIdx-1); var dispMsg = circleMsg+spliceStr; mContainer.removeChild(mContainer.lastChild); mContainer.appendChild(document.createTextNode(dispMsg)); prevMsg = circleMsg+'|'+spliceStr; setTimeout("updateMessage()",speed); }
function startCrawl(){
mContainer.appendChild(document.createTextNode(message)) setTimeout("updateMessage()",3000); // delay before crawl start; }
I have a created a list that has both live links and links that return false and go nowhere. On the latter I want to be able to remove the arrow that is shown in the circle and hints at navigation - but I want to keep it for the live links. As an aside to this how can I then stretch the settings box for the text as it appears to only stretch across 75% on the text.
I am looking to use the outputted data of the US Census' world population clock as the raw data for a javascript function on another site - does anyone know if it is possible, looking at their site?
I can't figure out this math problem. I have two points p1(30, 20) and p2(30, 221) and the parametric equation of the vector is (x-30)/(30-30)=(y-20)/(20-221)=t x=30, y=20-201*t
I'm thinking t is the magnitude or the distance. For a point P which is 10 pixels away from p1 on the vector, x=30, y=20-201*-10 (should be around -0.85) which is not the right P i'm looking for. Where am i doing wrong?
I 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.Below is the math equation I have come up with:
//calculate days from date field function calcTotal(date1, date2) { //assign variables
I am new to using Javascript and have been trying to incorporate this equation into my if statement but cannot get it to calculate properly no matter which method I use. Here is the function as I have it worked out presently.
I've got a Google map that allows you to enter your postcode and shows results within a certain radius of that point - a very common application of the API.I have it plotting a circle to represent the area covered (easy enough), but I'd like to "grey out" the map (e.g. by applying a semi-transparent layer over it) except for the area within the circle, which shows the map as normal.
This works perfectly fine for me, but this is a web-app that will be exposed to public users, and I obviously don't want them being able to eval anything if i can help it.
I'm using an ActiveX control in my html page.. Each time i load the page ie pops a message box to allow the activex to run or not . Is there any way to handle that message box using javascript. Or is there any other way to avoid that message box because each time the page loads i have to give yes and then proceed. By default i've to give yes is there any way to handle that using javascript.
I wrote this function to avoid the enter key in some of my textboxes. In IE the function works as expected, in Netscape 6 or 7 it does not work. How can I make my function works in both IE and Netscape.
I have to access a website which does a stupid browser check and only accepts Netscape 4.7. The problem is that I have to access the website with Mozilla or Internet Explorer. Code:
w3schools has ' Try it Yourself ' tab when visitors can edit code for tutorial.i wanna doing this type of function and i have already done but only a problem facing.An additional code Website Analytic Code always appears in my ' Try It Yourself ' textarea field.how can i avoid this additional code?
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:
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?
I want to know how to avoid inserting multiple records. Below is my case;
(1) I have a jsp page - when a timer for a particular product reaches 3 mins, i am getting that particular productid and sending the productid through ajax
(2) in the ajax script, i am getting the product id and redirecting to a jsp page
(3) in that jsp page, i am inserting a record to a table for that particular productid. Everything works fine, but many records are inserting, i just want to insert only one record.how to stop or avoid inserting multiple records.
Say that you have a table with id Testresults. Now you also would like to show diffrent parts of that table inside diffrent divs that also contain a table.
I naturally don't want to write the code for the table at multiple places of the page. Notice also that my site only contains of one site, containing many divs.
I want to know how to avoid inserting multiple records. Below is my case;
(1) I have a jsp page - when a timer for a particular product reaches 3 mins, i am getting that particular productid and sending the productid through ajax
(2) in the ajax script, i am getting the product id and redirecting to a jsp page
(3) in that jsp page, i am inserting a record to a table for that particular productid. Everything works fine, but many records are inserting, i just want to insert only one record.
I have a hyperlink that is draggable (using Prototype's "new Draggable()" construct). I want to be able to drag the link without actually 'clicking' the link once i end the drag. Is there a way to disable this event? Code:
var category_list = document.getElementById('category_list'); var dom_div = document.createElement('div'); dom_div.id = 'content' var dom_link = document.createElement('a'); dom_link.href ='#' dom_link.onclick = displayDiv(); val = document.createTextNode('Click'); dom_link.appendChild(val); dom_div.appendChild(dom_link); category_list.appendChild(dom_div);
The displayDiv Funcion
function displayDiv() { dv = document.getElementById('content'); //Here is the error. }
The Problem is when the following script:
dom_link.onclick = displayDiv('content'); is executed it is calling the function displayDiv(name) Here we have the code document.getElementById('content'); which throws the error.
The reason is the div container is not yet created.
What I need is the function should be called only on the click event. It should not be called while I define it to the Click Event. (ie it should not be called at the time of defining) How to achieve this.
I have developed a plugin for mutual selection on a list of elements.It works fine if I make those element into mutual list only once. like $("appropriateSelector").toMutualSelect(); that plugin will add click event handler to each element and they remember the whole list by enclosure.
If I add new elements to that list. and do$("appropriateSelector").toMutualSelect(); again. New elements will behave as expected but old ones will have problems. Each old element will have the same handler bind multiple times to them. That will result like toggle two times andmessingup the outcome. How do I prevent this? I am trying to clean up their bound handlers but seems no luck.
I have a text box and everytime I press enter on it I get the form submited. How can I avoid that behaviour? I tried: for the text onKeyDown="donotsubmit()" Code: function donotsubmit { var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; //alert(keyCode); if (keyCode == 13) { document.form1.submit()=false; }// if } But dosen't seem to work.