/    Sign up×
Community /Pin to ProfileBookmark

Help with adding to numerical values

Basically I have a numerical value (lets say £11.60 for example) that is passed to another page (ie booking.html?price=£11.60). What I want is for that value to have a certain number added to it. The code below is what I have tried to do this, but I only get the value with the numbers added to the end of it (ie £11.605 instead of £11.65). Ive asked other forums but they couldnt help me.
Below is the code which I need help with.
I need the .replace to stay there as it filters out the random characters that appear because of “spaces” that are passed along with the other variables.
Ive tried parseint() and parsefloat() but always get NaN as a result.

Anyone know a solution?

[quote]

if ( p[0] == ‘price2’ ) {
document.getElementById(“3”).innerHTML = p[1];
document.getElementById(“77”).innerHTML = p[1];
document.getElementById(’77’).value = document.getElementById(‘3’).innerHTML;
document.getElementById(“4”).innerHTML = p[1]+ 5;
document.getElementById(‘4′).value = document.getElementById(’77’).innerHTML;
document.getElementById(“5”).innerHTML = p[1]+ 15;
document.getElementById(‘5′).value = document.getElementById(’77’).innerHTML;

document.getElementById(“3”).innerHTML = p[1].replace(‘+’, ‘ ‘).replace(‘%C2%A3’, ‘£’).replace(‘ UK’, ‘ ‘);
document.getElementById(“77”).innerHTML = p[1].replace(‘+’, ‘ ‘).replace(‘%C2%A3’, ‘£’).replace(‘ UK’, ‘ ‘);
document.getElementById(“4”).innerHTML = p[1].replace(‘+’, ‘ ‘).replace(‘%C2%A3’, ‘£’).replace(‘ UK’, ‘ ‘)+5;
document.getElementById(“5”).innerHTML = p[1].replace(‘+’, ‘ ‘).replace(‘%C2%A3’, ‘£’).replace(‘ UK’, ‘ ‘)+15;

[/quote]

[URL=”http://www.edgwarelocalcars.co.uk/Booking2.html?address1=garth+road+nw2%C2%A0UK&address2=high+street+ha8%C2%A0UK&price2=%C2%A313.60&addfrom=%3Cstrong%3EFrom%3A+%3C%2Fstrong%3EGarth+Rd%2C+Barnet%2C+Greater+London+NW2+2%2C+UK%3Cbr%3E+&addto=%3Cstrong%3ETo%3A+%3C%2Fstrong%3EHigh+St%2C+Greater+London+HA8+7%2C+UK+%3Cbr%3E”]http://www.edgwarelocalcars.co.uk/Booking2.html?address1=garth+road+nw2%C2%A0UK&address2=high+street+ha8%C2%A0UK&price2=%C2%A313.60&addfrom=%3Cstrong%3EFrom%3A+%3C%2Fstrong%3EGarth+Rd%2C+Barnet%2C+Greater+London+NW2+2%2C+UK%3Cbr%3E+&addto=%3Cstrong%3ETo%3A+%3C%2Fstrong%3EHigh+St%2C+Greater+London+HA8+7%2C+UK+%3Cbr%3E[/URL]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 27.2010 — Numeric ID's are invalid.

You use innerHTML and value on the same element. Is this a list element?
Copy linkTweet thisAlerts:
@stylishjmauthorJan 27.2010 — Ive set it out like that because I needed the price to be displayed 3 times, with two (4 and 5) having something added to them. 77 is the id for a hidden input so that I can send the price to another page after that.

To you it must look like a mess, but it was the only way I could (almost) get it to work.

As for list element, Im assuming you mean that "3" "4" & "5" and yes they are part of a list.
Copy linkTweet thisAlerts:
@FangJan 27.2010 — var currency = '£11.65';
var addedValue = 0.05;
var needle = /(d+.+d+)/ig;
currency.match(needle);
document.getElementById('foo').value = String.fromCharCode(163) + (RegExp.$1*1 + addedValue).toFixed(2);
×

Success!

Help @stylishjm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...