Can we add function to textbox in dynamic table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinodsk101
    New Member
    • Oct 2008
    • 9

    Can we add function to textbox in dynamic table.

    Hi all,
    I am working on Dynamic table.
    I am creating the new row each time by using add button.
    But i in each row i am adding new text boxes, i want to add function to
    these textboxes like onclick="dosome fuction()" like this.
    The code look like this:

    Code:
    function createNewTextBox(){ 
    var myTable=document.getElementById('myTable'); 
    var plastron=myTable.rows.length; 
    var rows = myTable.getElementsByTagName('tr'); 
    var cels = rows[plastron-1].getElementsByTagName('td'); 
    var row = myTable.insertRow(plastron); 
    var cell = row.insertCell(1); 
    var el = document.createElement('input'); 
    else('type', 'text'); 
    else('name','myName'); 
    else('value', ''); 
    else('size', '10'); 
    else('maxLength', '10'); 
    el.onchange = function (evt) { anyFunctionThisTextBoxMightNeed() };
    cell.appendChild(el);
    el.onchange = function (evt) { anyFunctionThis TextBoxMightNee d() };
    In this perticular line i have added my function just like this,
    el.onchange = function (welcome) { alert("Welcome" ); };

    But code is not working.
    Please help me!!

    Thanks in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    When you say it's not working, is there an error?

    Are you trying to alert the passed variable?

    Comment

    • vinodsk101
      New Member
      • Oct 2008
      • 9

      #3
      No i am not passing any value. I just declared the function name and method.
      Its just telling object required error.
      Basically i want to add function to all textbox in table.
      Cau you tell me that, whether the code is proper or not!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Try:
        Code:
        el.onchange = function () { alert("Welcome"); };

        Comment

        • vinodsk101
          New Member
          • Oct 2008
          • 9

          #5
          Thank you its working.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Glad it is! You're welcome, of course.

            Comment

            Working...