OK heres the code - if ( p[0] == 'price2' ) {
-
document.getElementById("3").innerHTML = p[1];
-
document.getElementById("4").innerHTML = p[1] + 5;
-
document.getElementById("5").innerHTML = p[1] + 15;
-
document.getElementById("3").innerHTML = p[1].replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' ');
Basically the code underlined is what I need help with.
The p[1] is the price taken from a previous page and what I need it to do is to add it to the value. At the moment it is just adding iti to the end of the number. For example if p[1] is 10, then on the first underlined line the result would be 105, the second it would show 1015. http://www.edgwarelocalcars.co.uk/Booking2.html 20 3011
Use parseInt() -
document.getElementById("3").innerHTML = parseInt(p[1]);
-
document.getElementById("4").innerHTML = parseInt(p[1]) + 5;
-
document.getElementById("5").innerHTML = parseInt(p[1]) + 15;
Whatever the value you fetch from input,it will be considered as a string. To convert string to an integer use parseInt()
Thanks and Regards
Ramanan Kalirajan
that’s silent type casting, since the + operator is used for addition and concatenation. try 5 + p[1], or if that doesn’t help use parseFloat() or parseInt().
Ok great, now with the .replace lines in my original post, would I have to enter the parseInt and the + whatever amount or would that just apply for the
document.getElementById("4").innerHTML = p[1] for example.
Update: Just tried with the ones without the .replace and it only shows the orignal value with nothing added. Then tried - document.getElementById("5").innerHTML = parseFloat(p[1]).replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' ')+15;
and the results come up as NaN http://www.edgwarelocalcars.co.uk/Bo...e2=%C2%A310.00
(by the way please dont press book as im using a trial formmail account)
Update: Just tried with the ones without the .replace and it only shows the orignal value with nothing added. Then tried - document.getElementById("5").innerHTML = parseFloat(p[1]).replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' ')+15;
and the results come up as NaN
naturally. replace() is not a method of the Number object. change your parentheses: - document.getElementById("5").innerHTML = parseFloat(p[1].replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' '))+15;
still giving me NaN! - 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 = parseFloat(p[1])+ 5;
-
document.getElementById('4').value = document.getElementById('3').innerHTML
-
document.getElementById("5").innerHTML = parseFloat(p[1])+ 15;
-
document.getElementById('5').value = document.getElementById('3').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 = parseFloat(p[1].replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' '))+5;
-
document.getElementById("5").innerHTML = parseFloat(p[1].replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' '))+15;
line 5/7 or 12/13?
and what is p[1]?
PS. terminate every statement with a semi-colon and technically, IDs must not start with a number.
and what is p[1]?
params[p[0]] = p[1];
line 5/7 or 12/13?
Both im guessing. Im not too good with code so if possible, you will have to look at the source code of the link i posted in the previous post
Both im guessing. Im not too good with code so if possible, you will have to look at the source code of the link i posted in the previous post
look it up in the error console
and what is params[]?
Nothing coming up on error console and params[] Im not sure what it is or what it does but someone who wrote the code for me had it there for a reason. If you read the whole thread everything was working fine untill I needed to use the parseint / parsefloat to get the values to add
do you have a page, where I can look at that?
from first glance, p[1] is the wrong URL parameter (letters usually give NaN in parseFloat())
OK what would I have to chage it to? Is there an alternative to parsefloat?
the alternative is not using p[1], but the correct value.
the incorrect thing is: p[1] = "ha8+7ej%C2%A0UK"
so I would put this instead for example?
document.getElementById("5").innerHTML = parseInt(price2.replace('+', ' ').replace('%C2%A3', '£').replace(' UK', ' '))+15;
Edit: Still comes up with NaN
of course, parseFloat("ha8") naturally returns NaN.
in the example I showed in the post before this one, the value is 'price2' which is the id of the variable passed over that I need to be "parsed" yet it still doesnt work. It doesnt contain any addresses or what not, just numbers and "£" sign.
tip: check your html
works neither in Chrome nor Safari
Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7 - Booking2.html:189
findings from Dragonfly: p[1] = "%A311.60" which is parsed into NaN, or in other words, your replace search string doesn’t match.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: yukatan |
last post by:
Maybe it's a newbie question, but if I have two strings, let's say s1="4"
and s2="5", how can I get a new string of value "9", that is, add the two
numbers. If I type:
var newStr = s1 + s2
all I...
|
by: Frank |
last post by:
I have a large form, that has text boxes of numbers in rows and
columns. I need to sum the values in the columns, and put the total at
the bottom of the column. But I also need to sum the values in...
|
by: Stormkid |
last post by:
Hey Gang, I'm trying to figure out the best way to add two times together of
the format hh:mm:ss any suggestions would be great thanks Todd
|
by: Michael Hill |
last post by:
Hi, folks.
I am writing a Javascript program that accepts (x, y) data pairs from
a text box and then analyzes that data in various ways. This is my
first time using text area boxes; in the past,...
|
by: laredotornado |
last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to
have my Javascript function execute from the BODY's "onload" method,
but if there is already an onload method defined, I would...
|
by: Kyle Friesen via AccessMonster.com |
last post by:
Hello,
I have two fields (Customer and Product) which I need to track or assign an "ID number" to. For example, when Customer A has its first Product Y entry, then AY1. When Customer B has its first...
|
by: Martin McCormick |
last post by:
Most of the C programming I write manipulates strings so I haven't had
much experience with numerical functions and passing variables in and
out which brings me to a laughably simple problem that I...
|
by: rdemyan via AccessMonster.com |
last post by:
I have a table with about 80 fields. I'm using an import process to populate
the table. It works fine, except for the following:
Users generally don't specify values for a lot of numerical...
|
by: joanne matthews (RRes-Roth) |
last post by:
I'm getting different results when I add up a list of floats depending
on the order that I list the floats. For example, the following returns
False:
def check():
totalProp=0
inputs=
for each...
|
by: robinsiebler |
last post by:
I've never had any call to use floating point numbers and now that I
want to, I can't!
*** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) on win32. ***
0.29999999999999999
0.29999999999999999
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |