www.webdeveloper.com
Results 1 to 4 of 4

Thread: Calculate outside form, help!

  1. #1
    Join Date
    Apr 2012
    Posts
    12

    Calculate outside form, help!

    Right, basically I want "inputC" to be the value of the calculation without having to put it within form tags, any ideas?!

    Code:
    <form TheForm>
    <input type="text" name="inputA">
    <input type="text" name="inputB">
    <input type="button" value="Calculate" onClick=calculate()>
    </form>
    
    <script type="text/javascript">
    
    function calculate() {
    var A = document.TheForm.inputA.value;
    var B = document.TheForm.inputB.value;
    var C = A*B;
    
    }
    
    </script>
    
    <input type="text" name="inputC">

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    HTML Code:
    <input type="text" name="inputC" id="inputC">
    Code:
    <script type="text/javascript">
    
    function calculate() {
    var A = document.TheForm.inputA.value;
    var B = document.TheForm.inputB.value;
    var C = A*B;
    document.getElementById('inputC').value=C;
    }
    
    </script>

  3. #3
    Join Date
    Apr 2012
    Posts
    12
    Thanks, it works perfectly!

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    anytime ))

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