newphpcoder Posted May 9, 2012 Share Posted May 9, 2012 Hi... I have problem in event handler.. Now my form is when I input data to Max Lot the Max Total was auto change and the Max Doz was change, but the Total of Max Doz was not change Now my question is what eventhandler should I use to make the Total of Max Doz was also change. The total of max was change because I input data on that textbox but the data in Max Doz was not inputted it automatically displayed output. here is my sample code: <script type="text/javascript"> //Auto convert to Doz and auto compute total max doz=====//// function doz(oText){ if (isNaN(oText.value)) //filter input { //alert('Numbers only!'); oText.value = ''; } var field, val, oForm = oText.form, Total_max_doz = a = 0; for (a; a < arguments.length; ++a) //loop through text elements { field = arguments[a]; val = parseFloat(field.value); //get value if (!isNaN(val)) //number? { Total_max_doz += val; //accumulate } } oForm.Total_max_doz.value = Total_max_doz.toFixed(2); //out } </script> <tr> <td><input type="text" name="P28" id="P28" value="P28" style="text-align: left; border: none;" size="6" maxlength="7" readonly="readonly"></td> <td><input type="text" name="P28_bch_wt" id="P28_bch_wt" size="8" maxlength="7" style="text-align: right;" value="<?php echo $P28_bch_wt; ?>" onKeyUp="return autobch(this, P30_bch_wt, P32_bch_wt, P33_bch_wt, P35_bch_wt, P35M_bch_wt, P35W_bch_wt, P38_bch_wt, P41_bch_wt, P42_bch_wt, P43_bch_wt, P46_bch_wt, P47_bch_wt)"></td> <td><input type="text" name="P28_bch_uom" id="P28_bch_uom" value="Kg" style="text-align: left; border: none;" size="2" readonly="readonly"></td> <td><input type="text" name="P28_plug_wt" id="P28_plug_wt" style="text-align: right;" size="8" maxlength="7" value="<?php echo $P28_plug_wt;?>" onKeyUp="return plug(this, P30_plug_wt, P32_plug_wt, P33_plug_wt, P35_plug_wt, P35M_plug_wt, P35W_plug_wt, P38_plug_wt, P41_plug_wt, P42_plug_wt, P43_plug_wt, P46_plug_wt, P47_plug_wt)"></td> <td><input type="text" name="P28_plug_uom" id="P28_plug_uom" value="g" style="text-align: left; border: none;" size="1" readonly="readonly"></td> <td><input type="text" name="P28_max_lot" id="P28_max_lot" size="8" maxlength="7" style="text-align: right;" value="<?php echo $P28_max_lot; ?>" onKeyUp="return autocalearn(this, P30_max_lot, P32_max_lot, P33_max_lot, P35_max_lot, P35M_max_lot, P35W_max_lot, P38_max_lot, P41_max_lot, P42_max_lot, P43_max_lot, P46_max_lot, P47_max_lot)"></td> <td><input type="text" name="P28_max_lot_uom" id="P28_max_lot_uom" value="Lot" style="text-align: left; border: none;" size="3" readonly="readonly"></td> <td><b><input type="text" name="P28_max_doz" id="P28_max_doz" maxlength="12" style="text-align: right; border: none; font-weight: bold;" size="12" readonly="readonly" value="<?php echo $P28_max_doz;?>" onkeyup="return doz(this, P30_max_doz, P32_max_doz, P33_max_doz, P35_max_doz, P35M_max_doz, P35W_max_doz, P38_max_doz, P41_max_doz, P42_max_doz, P43_max_doz, P46_max_doz, P47_max_doz)"></b></td> </tr> as you can see I use onkeyup in function doz() when I tried oonchnage it did not change. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/262279-problem-in-event-handler/ Share on other sites More sharing options...
gizmola Posted May 9, 2012 Share Posted May 9, 2012 If I understand you, the doz function recalculates based on the values of other inputs, and like a spreadsheet you want these calculations to cascade. Events fire based on user actions. There is no event that fires when the value of an input changes. What you should do, is call your doz function in your other event handlers, so that your summarization function runs. Quote Link to comment https://forums.phpfreaks.com/topic/262279-problem-in-event-handler/#findComment-1344139 Share on other sites More sharing options...
newphpcoder Posted May 9, 2012 Author Share Posted May 9, 2012 I call it using onkeyup = doz(); Thank you Quote Link to comment https://forums.phpfreaks.com/topic/262279-problem-in-event-handler/#findComment-1344142 Share on other sites More sharing options...
gizmola Posted May 9, 2012 Share Posted May 9, 2012 I call it using onkeyup = doz(); Thank you That is a user generated event! Is it your design that you change an input, and then the user has to visit some other input, using some non-intuitive unconnected key to get the behavior you are looking for? I'd hate to be the user of your application, stumbling around pressing keys on random inputs hoping that something will work correctly..... My advice to you is to use firebug and debug your code, if you're not clear on why something doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/262279-problem-in-event-handler/#findComment-1344148 Share on other sites More sharing options...
newphpcoder Posted May 9, 2012 Author Share Posted May 9, 2012 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/262279-problem-in-event-handler/#findComment-1344153 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.