www.webdeveloper.com
Results 1 to 3 of 3

Thread: what is wrong with this?

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Posts
    15

    Question what is wrong with this?

    Hello everybody
    Can somebody tell me what is wrong sith this code?
    Very new to JS and about to shoot myself.


    Simple script to pick values form several texboxes (named PMV[1], PMV[2], PMV[3] from form (TTTForm) and add them up and show them in another texbox with click of a button:


    <script type="text/javascript">
    <!--
    function Addup()
    {
    var PMNUMBR = 3;
    var VTOTAL = 0 ;

    for (var i=1;i<=PMNUMBR;i++)
    {
    VTOTAL = VTOTAL + parseFloat(document.TTTForm["PMV[i]"].value);
    }
    document.TTTForm.TotalBox.value=VTOTAL;
    return
    }
    //-->
    </script>

    here is the button;

    <input type=button onclick="Addup()" value="Calculate">

    here is the textbox:

    <input type=text name=TotalBox>
    Last edited by JayJava; 12-11-2012 at 09:22 PM.

  2. #2
    Join Date
    Dec 2012
    Posts
    97
    You need to change this line

    VTOTAL = VTOTAL + parseFloat(document.TTTForm["PMV[i]"].value);

    To

    VTOTAL = VTOTAL + parseFloat(document.TTTForm["PMV["+i+"]"].value);

    You're literally looking for an input with the name "PMV[i]" rather than using the variable i

  3. #3
    Join Date
    Dec 2012
    Posts
    15
    1000,000,000 times thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles