Home > Back-end >  Script fired issue on input-text change
Script fired issue on input-text change

Time:04-17

Very basic stuff, but I don't understand why when I'm using this code it doesn't work. Many tutorial use it and I believe that they can't be all wrong.

$("#username").focusout(function(e) {
  e.preventDefault();
  // get the nickname
  var nick_name = $(this).val();
  console.log(nick_name);
});
<input type="text" onchange="valueChanged()" required="" name="username" maxlength="150" id="id_username" autofocus="">

CodePudding user response:

Stop downvote question. If we asked question, it's because we want to learn and get better. Everything I learned was by myself and obviously downvoting question is dirty.

The real thing is such as Blessing Ladejobi learn me today, to reference by ID using jQuery "$#id_your_id" is the way yo go.

Thank for this gentleman

CodePudding user response:

I believe you only have a minor mistake in your code.

<script>
//The ID you selected here is username but from your html it is supposed to be id_username
$("#username").focusout(function(e) {
    e.preventDefault();
    // get the nickname
    var nick_name = $(this).val();
    console.log(nick_name);
});

so instead try this:

$("#id_username").focusout(function(e) {
        e.preventDefault();
        // get the nickname
        var nick_name = $(this).val();
        console.log(nick_name);
    });

  • Related