Form Values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • portchey

    Form Values

    Hi,

    Excuse my lack of knowledge about javascript, I have a question that
    I'm stumped on.

    I have a form that has many text boxes that the user enters the
    quantity of an item. Each item has a unit value.
    How do I display on the page the total value of each item next to each
    text box as the user enters the quantity in each text box in turn.

    I feel the "onblur" event may be the event to use for each text box but
    can't seem to get the calculated value displayed on the page.

    Thanks for any advice.

    Phil.

  • VK

    #2
    Re: Form Values



    portchey wrote:[color=blue]
    > I have a form that has many text boxes that the user enters the
    > quantity of an item. Each item has a unit value.
    > How do I display on the page the total value of each item next to each
    > text box as the user enters the quantity in each text box in turn.[/color]


    <html>
    <head>
    <title>Calculat e</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <script type="text/javascript">
    function recalculate(goo dy) {
    var output = document.getEle mentById(goody. id+'total');
    var quantity = goody.value;
    if (!isNaN(parseIn t(quantity,10)) ) {
    var price = goody.getAttrib ute('price');
    output.innerHTM L = quantity*price;
    }
    else {
    output.innerHTM L = 0;
    }
    }
    </script>
    </head>

    <body bgcolor="#FFFFF F">

    <form name="myForm">
    <label for="item001">I tem 1:</label>
    <input type="text" name="item001" id="item001"
    size="3" maxlength="3" value="0" price="25"
    onfocus="this.s elect();"
    onkeyup="recalc ulate(this);">
    <span>Total: $<span id="item001tota l">0</span></span>
    </form>

    </body>
    </html>

    Comment

    • portchey

      #3
      Re: Form Values

      Hi VK,

      Thanks very much for the example script.
      I'll give it a go.

      Phil.

      Comment

      • portchey

        #4
        Re: Form Values

        Hi all,

        How would I apply the same process but use a drop down menu for the
        quantity instead of entering the value in a text box.

        Thanks very much for any guidence.

        Phil.

        Comment

        • Randy Webb

          #5
          Re: Form Values

          portchey said the following on 8/4/2005 4:34 PM:[color=blue]
          > Hi all,[/color]

          I'm not "all" but hi.
          [color=blue]
          > How would I apply the same process but use a drop down menu for the
          > quantity instead of entering the value in a text box.[/color]

          "Same process" as what? Quote what you are replying to and that becomes
          self-evident.
          [color=blue]
          > Thanks very much for any guidence.[/color]

          Guidance: Read the group FAQ, thoroughly.

          --
          Randy
          comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

          Comment

          Working...