Saturday, 15 May 2010

javascript - Independent button -



javascript - Independent button -

i have javascript code creates buttons onload attributes beingness values asp page fetches database. whatever event want each button do, other buttons , executes before buttons displayed. please help...

function createbuttons(tbid, tbclass, tbtype, tbvalue, onclick) { homecoming '\n<input' + (tbid ? ' id=\'' + tbid + '\'' : '') + (tbclass ? ' class=\'' + tbclass + '\'' : '') + (tbtype ? ' type=\'' + tbtype + '\'' : '') + (tbvalue ? ' value=\'' + tbvalue + '\'' : '') + (onclick ? ' onclick=\''+ onclick + '\'':'') + '>'; } function displaybuttons(cabledata) { var newcontent = ''; $.each(cabledata, function (i, item) { newcontent += createbuttons(item.commoncable, null, "submit", item.commoncable,alert("clicked")); }); $('#categories').html(newcontent);

}

do not phone call "alert('clicked')" (or whatever action want execute when button clicked) in function phone call creates button, or executed right away. instead, create anonymous function , wrap phone call in it. e.g.

newcontent += createbuttons(item.commoncable, null, "submit", item.commoncable,"alert('clicked')");

edit: didn't notice build button html text. in case pass code want execute (function call) text. edited code above reflect this.

javascript

No comments:

Post a Comment