Procuct with decimal

F

Fra

Hi, I've a problem with a product between 3 input field

<form name="Form1" method="post" action="" >


<input name="lit" type="text" id="lit" disabled="disabled"/>

<input name="ore" type="text" id="ore" HIDDEN/>

<input name="qt" type="text" id="qt"/>

<input name="totale" type="text" id="totale" />

</form>

I would like to make a product

"lit*qt*ore" and write it in "totale"

but:

1) It must consider decimal number (with 2 decimal) with "," decimal symbol
(not ".")

2) To see an Alert if an user inserts a char (a,b,c,d,e...) and tranform it
in a 0 (for example) ... if user inserts "," this char wil be allowed
because I must allow decimal product


example:
lit: 1,23
qt: 2
ore: 2,50

in totale will write: 6,15


I hope you can help me!!
 
L

Lee

Fra said:
Hi, I've a problem with a product between 3 input field

<form name="Form1" method="post" action="" >


<input name="lit" type="text" id="lit" disabled="disabled"/>

<input name="ore" type="text" id="ore" HIDDEN/>

<input name="qt" type="text" id="qt"/>

<input name="totale" type="text" id="totale" />

</form>

I would like to make a product

"lit*qt*ore" and write it in "totale"

but:

1) It must consider decimal number (with 2 decimal) with "," decimal symbol
(not ".")

2) To see an Alert if an user inserts a char (a,b,c,d,e...) and tranform it
in a 0 (for example) ... if user inserts "," this char wil be allowed
because I must allow decimal product


example:
lit: 1,23
qt: 2
ore: 2,50

in totale will write: 6,15


I hope you can help me!!

If you're going to get anything out of this assignment, you should
try your best before asking for help. Show us what you've got so
far.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sun, 17
Jul 2005 10:52:45, seen in Fra
1) It must consider decimal number (with 2 decimal) with "," decimal symbol
(not ".")

See said:
2) To see an Alert if an user inserts a char (a,b,c,d,e...) and tranform it
in a 0 (for example) ... if user inserts "," this char wil be allowed
because I must allow decimal product

Consider
OK = !/[^\d,\.]/.test(F.X0.value)
if (OK) Numero = +F.X0.value ; else { Numero = 0 ; alert(0) }

and <URL:http://www.merlyn.demon.co.uk/js-valid.htm>


GENERAL : <FAQENTRY> : note that the unary + converts an empty string to
zero; that may be convenient or otherwise.

When posting the "same" article in English in comp* and in Italian in
it*, please say that you are doing so. Your request will be easier to
understand if it can be viewed in both languages, and if one sees a good
answer in either language one will not need to reply in the other.

CROSS-POSTED.
 
F

Fra

I've created this

<script>
function Calc() {
var costo = parseFloat(Form1.costoTerzi.value.replace(/\,/g,'.'));
var qt = parseFloat(Form1.quantita0.value.replace(/\,/g,'.'));
var totale = (costo * qt)

document.Form1.Anno1.value = totale
}
</script>


but:

How Can I see the "," and not "." in the *
How Can I see an error message in an user inserts char "abcdefg..." and to
change the char in "0"

Thanks
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 19
Jul 2005 10:34:37, seen in Fra
var qt = parseFloat(Form1.quantita0.value.replace(/\,/g,'.'));
var qt = parseFloat(Form1.quantita0.value.replace(/,/, '.'));
How Can I see the "," and not "." in the *

document.Form1.Anno1.value = String(totale).replace(/\./, ',')

document.Form1.Anno1.value = totale.toString().replace(/\./, ',')

How Can I see an error message in an user inserts char "abcdefg..." and to
change the char in "0"

Already indicated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top