JavaScript
x
10
10
1
//<![CDATA[
2
$(window).load(function() {
3
4
$('.n_val').focusout(function() {
5
alert(this.id);
6
7
});
8
9
});//]]>
10
To generate textbox dynamically
JavaScript
1
2
1
buffer += "<tr><td>" + nomen_list.getName() + "</td><td><input type='text' style='width:50px' class='n_val' id=" + nomen_list.getId() + "-" + nomen_list.getCat() + " value=" + nomen_list.getVal() + " /></td></tr>";
2
I getting dynamically textbox, but focusout
is not working for dynamically generated textbox, whereas same page has some textbox, which is hard-coded for that, above script gets triggered.
Advertisement
Answer
JavaScript
1
6
1
$(window).load(function() {
2
$(document).on('focusout','.n_val',function() {
3
alert(this.id);
4
});
5
});
6
Instead of using document you could use the text box’s closest parent id or class. I have no idea of your html layout, hence using document. Also see jQuery on.