Create a table dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anudu
    New Member
    • Oct 2007
    • 31

    Create a table dynamically

    hi ,

    I am developing a system using javascripts and ajax.
    I am retrieving data from database and bind them in an html table. I am using a for loop to do this. This table has one column of html buttons. my task is to call a function when a user press the button in a row. this function will call an ajax method to bring some data fro the database. I have to pass a value to this function when a user press the button. this value is unique to each raw.

    this is the part code i am trying;


    [CODE=javascript]// in the for loop

    btn=document.cr eateElement('IN PUT');
    btn.type='butto n';
    btn.value=Dset. value.Tables[0].Rows[a].CusCode;

    btn.onclick=fun ction CustomerClick()
    {
    // function will bring data
    };

    //
    [/CODE]

    this is the place i got the problem. I want to pass that 'CusCode' value to the function as avariable. this 'CusCode' is unique to each raw. when the user press the button it should call the function with it's unique variable.

    can anyone help me to solve this?
    Last edited by gits; Mar 13 '08, 09:17 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    try this:

    [CODE=javascript]
    var btn = document.create Element('INPUT' );
    btn.type = 'button';
    btn.value = Dset.value.Tabl es[0].Rows[a].CusCode;

    btn.onclick = function(value) {
    return function() {
    // here use value which is the closured btn.value
    };
    }(btn.value);
    [/CODE]
    kind regards

    Comment

    • anudu
      New Member
      • Oct 2007
      • 31

      #3
      wow, it works perfectly. Thank you very much.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        no problem :) .... post back to the forum anytime you have more questions ...

        kind regards

        Comment

        Working...