0

I click on the first button which gives me a popup with another button to be clicked. When I click on that second button, I want the condition to be checked and return an alert.

#chkValid - first button ID
#okButton - second button ID

jQuery("#chkValid").on("click", viewSomething);

function viewSomething() {
  jQuery("#okButton").click(function() {
    if (jQuery('#Field_6').val() != "MD") {
      alert("It has to be MD");
    }
  });
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
tabs
  • 31
  • 1
  • Your code seems fine in isolation. Do you have a specific issue with it? Seeing a working example including all relevant HTML and CSS in a snippet may help us to debug it. – Rory McCrossan Jul 28 '21 at 18:16
  • Only the first function works after page load, second button click doesn't show me an alert. Even in firefox console , first click works. But if I put this code in the console after the first button is clicked, it works. – tabs Jul 28 '21 at 18:23
  • 1
    I'd suggest using delegated event handlers, as it's possible that the modal content is being dynamically created in the DOM. Again, this is a guess given the limited example code. – Rory McCrossan Jul 28 '21 at 18:25
  • yes this content is dynamically created so I can't post the code, hence I am using jQuery with button ID's . – tabs Jul 28 '21 at 18:37
  • `yes this content is dynamically created so I can't post the code` sure you can, copy+paste it from the DOM inspector if you need to. In either case, the issue is due to the lack of event delegation. See the duplicate for more information – Rory McCrossan Jul 28 '21 at 18:38

0 Answers0