ainoy31 Posted November 30, 2007 Share Posted November 30, 2007 Here is my scenario: I have four input fields and the first three is asking for the dimension in length, width, and height. The fourth input field will store the final calculation. <tr> <td>Dimensional inches to weight(kgs)</td> <td> <input type="text" name="len" class="len" size="3"> <input type="text" name="wid" class="wid" size="3"> <input type="text" name="hgt" class="hgt" size="3"> <input type="text" name="sum" class="sum" size="3"> </td> </tr> Then I have my javascript as: <script type="text/javascript"> $(document).ready(function() { $('.datepicker').datePicker(); $('input.len, input.wid, input.hei, input.sum').keyup(function() { calc_Dim_wgt(); }); }); function calc_Dim_wgt() { len = $(this).find('input.len'); wid = $(this).find('input.wid'); hgt = $(this).find('input.hgt'); sum = $(this).find('input.sum'); sum = len * wid * hgt; } </script> Any suggestion is much appreciated. AM Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 30, 2007 Author Share Posted November 30, 2007 OK. I am almost there. I am able to do the calculation after filling in the three fields but I still have to click on the fourth field to give me the total. I want to display the total after filling in the third field. Here is my code: <script type="text/javascript"> $(document).ready(function() { $('.datepicker').datePicker(); $('input.len, input.wid, input.hei, input.sum').keyup(function() { calculate_sum() }); }); function calculate_sum() { var length = document.getElementById('len').value; var width = document.getElementById('wid').value; var height = document.getElementById('hgt').value; var sum = length * width * height; sum_result(sum); } function sum_result(sum) { document.getElementById('sum').value = sum; } </script> Input fields: <input type="text" name="len" id="len" size="3"> <input type="text" name="wid" id="wid" size="3"> <input type="text" name="hgt" id="hgt" size="3"> <input type="text" name="sum" id="sum" size="3" onClick="calculate_sum();"> Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted November 30, 2007 Author Share Posted November 30, 2007 The solution is my previous note and I had to change the 'hgt' input field as follows: <input type="text" name="hgt" id="hgt" size="3" onKeyUp="calculate_sum();"> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.