Search code examples
jqueryajaxkeyup

jQuery keyup event not working from another php file


In main.php i call settings.php with ajax, inside settings there is one input text field with id #newlogintext, if i put the jquery keyup in settings.php it's working, but if i put it in main.php it's not.

in main php call settings.php :

function CheckSettings() {

$.ajax({
   type: 'POST',
   url: 'settings.php',
   data: form_data,
   success: function(data) 
   {
      $("#settings").html(data); 
   }
});
}
CheckSettings();

Keyup:

$( document ).ready(function() {
$("#newlogintext").on("keyup", function(){
alert("test");
});
});

Settings php:

<div class="settings">
<b> General Settings </b>
<br>
<p>New login:</p> <input id="newlogintext" type="text" name="newlogin" />
</div>

Solution

  • Please try this :
    $(document.body).on("keyup","#newlogintext",function(){
    alert("test");
    });