SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member davestott1's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Decimalise Form Field Using JS

    I have the code below on a page I am building

    Basically what I want to do is to have the last total field (with discounted price) show the value with 2 decimal places (for example 2.25 instead of 2.2535456)

    Is this possible using JavaScript and if so could anyone point me in the right direction?

    Thanks

    Dave

    (my code follows>)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    function discounter() {
    document.form1.total.value=document.form1.itemprice.value/100*10
    document.form1.discountedprice.value=document.form1.itemprice.value-document.form1.total.value
    }
    </script>
    </head>

    <body>
    <form name="form1" method="post" action="">
    <p>Item Price=
    <input name="itemprice" type="text" onChange="return discounter()" id="itemprice" size="5">
    </p>
    <p> With Discounted Price=
    <input name="discountedprice" type="text" disabled id="discountedprice3">
    <input name="total" type="hidden" disabled id="total">
    </p>
    </form>
    </body>
    </html>

  2. #2
    Old Folks 127.0.0.1 pacres's Avatar
    Join Date
    Sep 2003
    Location
    ed.ab.ca.na.ea
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this
    this.form.answer.value = Math.round(((this.form.cost.value-0)+.10)*100)/100">

  3. #3
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't double-post...

    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •