Procuct with decimal

Discussion in 'Javascript' started by Fra, Jul 17, 2005.

  1. Fra

    Fra Guest

    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!!
     
    Fra, Jul 17, 2005
    #1
    1. Advertising

  2. Fra

    Lee Guest

    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.
     
    Lee, Jul 17, 2005
    #2
    1. Advertising

  3. JRS: In article <1MqCe.78213$>, dated Sun, 17
    Jul 2005 10:52:45, seen in news:comp.lang.javascript, Fra
    <> posted :
    >
    >1) It must consider decimal number (with 2 decimal) with "," decimal symbol
    >(not ".")


    See <URL:http://www.merlyn.demon.co.uk/js-maths.htm#DPV>

    >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.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Jul 17, 2005
    #3
  4. Fra

    Fra Guest

    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
     
    Fra, Jul 19, 2005
    #4
  5. JRS: In article <1H4De.84063$>, dated Tue, 19
    Jul 2005 10:34:37, seen in news:it.comp.lang.javascript, Fra
    <> posted :

    >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.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Jul 19, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ven
    Replies:
    3
    Views:
    1,331
  2. Gilbert Fine
    Replies:
    8
    Views:
    908
    Zentrader
    Aug 1, 2007
  3. Vitaliy
    Replies:
    1
    Views:
    481
    Peter Otten
    May 29, 2008
  4. valpa
    Replies:
    11
    Views:
    1,526
    Steven D'Aprano
    Mar 24, 2009
  5. Replies:
    0
    Views:
    297
Loading...

Share This Page