April 28, 20188 yr I have a form where there is an input box with an ID. However, the ID is altered each time the form is run. The format is q?:1_answer where ? is an incremental value (for example, 11739, then 11740). I want to submit an automated response to the input box but cannot change it's behaviour. So, I need a line of Javascript that will identify the current ID for that instance of the input box on that particular moment in time. Anyone any ideas?
April 30, 20188 yr You can target the input by something other than an ID, e.g. a class or data-* attribute that will likely not be dynamic.
May 1, 20188 yr $id = $('#myform input').map(function() { return this.id; }).get(); This, I hope, should return the ID of any input element in your Form, if you have multiples it will return an array of IDs - but I think you just have one that dynamically updates, right? I'm at work, so I cannot actually test this. I hope it works for you. If you have multiple input elements, you will need to target the element based upon something like class, as Lyndsey suggested.
Create an account or sign in to comment