0

I have the below code with which I am basically syncing textbox value changes across various fields sharing the same class name. The issue is that this is not working in IE but working in Chrome. Can some please have a look and let me know what I am missing here.

My scenario : I have two tabs where I have textboxes..Initially the second tab is hidden and when user saves the page the without postback the second tab becomes available. So the second tab has textbox which when becomes visible is not being bound to the change event. If I refresh the whole page then the sync is working fine.

$(document).ready(function () {
  $(".txtDateFrom").keyup(function () {
        $(".txtDateFrom").val($(this).val());
    });    
});

Thanks

SP1
  • 1,182
  • 3
  • 22
  • 47
  • 1
    Try to use `$(".txtDateFrom").on("keyup", function () ) { ... }`. I have the feeling that this solves the issue ;) – Red Dec 09 '19 at 20:54
  • 1
    @Red, why? that is basically the same code – epascarello Dec 09 '19 at 20:55
  • @epascarello Yep, basically the same, but check this out https://stackoverflow.com/questions/9122078/difference-between-onclick-vs-click I think IE doens't recognize the input because its visibility is hidden. `Initially the second tab is hidden and when user saves the page the without postback the second tab becomes available.` I have the feeling IE interpret it as dynamically added ... – Red Dec 09 '19 at 20:57
  • 2
    @Red, well that is not going to get dynamically added elements. That is not the correct syntax. Your code is literally the same thing as the OPs code. There is no event delegation. Event delegation would be `$(document).on("keyup", ".txtDateFrom", function () ) { ... }` – epascarello Dec 09 '19 at 21:03
  • 1
    @Red The answer you've cited works because it's using event delegation. Notice how it attaches the event to the *container*, and passes the button as an argument to `.on()`. The code you suggested in your original comment does not do this, therefore it's merely a different way of writing the exact same thing that OP already wrote. – Tyler Roper Dec 09 '19 at 21:04

0 Answers0