By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Using OnClick to display message in textbox

P: 1
I want to add onClick() on a textbox which is dynamically generated in a table using following java script method.i just want to call a java script method which will get generate through this code.
suppose i want to show a message "hi" if anybody click on the textbox generated with this code.


Expand|Select|Wrap|Line Numbers
  1.   function addRow()
  2.   {
  3.  
  4.  var tbody = document.getElementById("table2").getElementsByTagName("tbody")[0]; 
  5. var row = document.createElement("TR"); 
  6. var cell1 = document.createElement("TD"); 
  7. var inp1 =  document.createElement("INPUT"); 
  8. inp1.setAttribute("type","text"); 
  9. inp1.setAttribute("name","game_"+count);
  10. inp1.setAttribute("id","game_"+count);
  11. inp1.setAttribute("maxlength",11);
  12. inp1.setAttribute("size",10);
  13. inp1.setAttribute("value",document.forms.form1.elements.game.value); 
  14. cell1.appendChild(inp1); 
  15. var cell2 = document.createElement("TD"); 
  16. var inp2 =  document.createElement("INPUT");
  17. inp2.setAttribute("type","text"); 
  18. inp2.setAttribute("name","number_"+count);
  19. inp2.setAttribute("id","number_"+count);
  20. inp2.setAttribute("maxlength",11);
  21. inp2.setAttribute("size",10);
  22. cell2.appendChild(inp2); 
  23. row.appendChild(cell1); 
  24. row.appendChild(cell2); 
  25. }
Sep 20 '06 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Expand|Select|Wrap|Line Numbers
  1. inp2.onclick = function() { alert('hi'); }
May 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.