0

I've seen tutorials on detecting changes on the values of input id, but is there a quick snippet or code that would update the input id name if it were to be changed? I'm sort of new in this and I did some research and found this code

setInterval(function() { ObserveInputValue($('#input_id').val()); }, 100);

Is it possible to detect if the name of an input id changes then automatically update and change the variable?

Example $('#myname').val('name').change(); If the input id changes to nameofperson, what code would automatically detect that and change the input id name to nameofperson?

MGames
  • 1,171
  • 2
  • 13
  • 24
  • This may help you out: http://stackoverflow.com/questions/6458840/on-input-change-event – Matthijs Nov 16 '16 at 07:07
  • Can you elaborate _Is it possible to detect if the name of an input id changes then automatically update and change the variable?_ – Satpal Nov 16 '16 at 07:08
  • @Satpal If the the name of an input id like username from a site changes to nameofuser then how would I get the my code to detect that the input id changed to nameofuser? – MGames Nov 16 '16 at 07:13

1 Answers1

0

It will indicate at time of id change in the input

var original="test";
setInterval(function() { // the will listen the id change or not
  var current = $('input').attr('id');
  if(original != current) //matching the id with previous id
    {
       original = current;
      console.log('id was changed your new id= '+current)
      }
 }, 100);

var count =0;
$('button').click(function(){
  $('input').attr('id','change'+count);//each time you click id was changed.
  count++;
  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="test" class="changing">
<button>changeId</button>
prasanth
  • 22,145
  • 4
  • 29
  • 53
  • Would the second block of code you wrote change the id after it detects a change? – MGames Nov 17 '16 at 00:46
  • Second block was change the `id` at time of click the button. setInterval match `previous id` and `current id` Finaly print the result if they are changed.First change they `id` .It auto detect with setInterval – prasanth Nov 17 '16 at 08:34