jquery - How to match id in javascript for dynamically added field on html? -


In our Rail app, the dynamic field can be added to the form. Here is an HTML source code for the dynamically added area order_order_items_attributes_1413563163040_unit_price :

   

As you can see, the field ID has 13 digits string and when randomly joining the field it is randomly generated. How can we match this type of random ID in JavaScript? The app uses jQuery Rail (former, $ ('# order_order_items_attributes_xxxxxxxxxxxx_unit_price'). Changes (function () {}) ).

We are new to this CSS type of ID match. More detail will be appreciated.

You have to first decide which algorithm you are using to match the ID Values. (This is not precistly specified in your question) Based on your comment, it appears that you find all the IDs that begin with "order_order_items_attributes_" and to find "_ unit_price" Ending with and wanting the sequence of digits between them

You can like it to find all the IDs you want and then filter for all those Matches only three criteria:

  // With this method Find El eater AIDS: order_order_items_attributes_xxxxxxxxxxxxx_unit_price var order Aitamreg x = / ^ order_supplier_id_ \ d + _unit_price $ /; . $ ("[Id ^ = 'order_supplier_id _']") filter (function (index) {orderItemRegex.test (this.id) return;}). Change (function () {// it will only match id}};  

It uses jQuery to create a list of all the objects that have an ID that starts with "order_supplier_id _" . This filter defines your pattern by filtering / ^ order_supplier_id_ \ d + _unit_price $ / through the list that destroys any items that do not match the full regular expression, and then .change up hook () event handler as well as regex test as well as objects.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -