Saturday, August 27, 2011

Working with form object in javascript

It took me three days to learn and come up with a solution of how to handle the event of updating a column based on any change in some other corresponding row with some operation being done.
For example,the following function takes the index 'k' of a text field in the first form in the document and handles two successively next text fields.It multiplies the integer entered in the text field at index 'k' with a float at index 'k+1' and writes in the text box at index 'k+2'.This can be done for any number of rows in the table provided the corresponding index is given.The function is as follows:

function total(k){
oForm = document.forms[0];
oText1 = oForm.elements[k];
oText2 = oForm.elements[k+1];
oForm.elements[k+2].value = parseInt(oText1.value) * parseFloat(oText2.value);
}

The radices may be checked according to use.
From html part,the above function can be called from the text box having index 'k'.I used 'onkeyup' to call this function with an index 'k' which had value according to the index of the text box.The reader may work on the probable index according to his/her use which may include the number of columns in the table.
Any other inputs from readers are welcome and appreciated.Thank you all for reading.

2 comments:

  1. wow its very exciting and enlightening...please share something more on this topic...

    ReplyDelete
  2. please post your views on ethical hacking....and your ideas about open source...

    ReplyDelete