Click to See Complete Forum and Search --> : RE: HOW to create a num String from 3 numbers???


nemo7111
01-23-2004, 07:44 AM
Hi, there ...

Can anybody give me a code of how to create a number which is later used in mathematical operation?

I have these numbers:

1) 788 ( this is a constant )
2) xxxxxxxxxx ( this is a form value entered by client )
3) 889 ( constant )


I want the JS to join these 3 numbers into one:

788xxxxxxxxxx889

Through which command ca I achieve this?

I wrote this but it is wrong:

var fusion = 788 + "" + input_value + "" + 889;

I think I used wrong operator "+". It seems to mathematically add these three values creating completely
different number.


???????

TheBearMay
01-23-2004, 07:55 AM
Try this (Note the quotes):

var constant1="788";
var constant2="889";
var fusion=constant1+input_value+constant2;

nemo7111
01-23-2004, 07:58 AM
Thanks,

1 more question:

How do I write "input_value" in code? I mean how exactly it is coded?

TheBearMay
01-23-2004, 08:06 AM
You've got a few choices depending on how you're getting the value.

From a prompt:
var input_value=prompt("Enter acct#","");

From a text box:
var input_value=tBox.value;
where tBox is defined in the body similiar to
<input type="text" id="tBox"....

IceMetalPunk
01-23-2004, 11:21 AM
Hi Nemo-
TheBear was right, but I thought you might want to know WHY it works this way. When you typed your first code, the constants (788 and 889) were not in quotation marks. This causes the computer to read it as numbers, and perform mathematical operations instead of joining them into one string. Putting them in quotes lets the computer know that you want it to put the STRINGS together, not add the NUMBERS together.

-IceMetalPunk;)