I am getting html after ajax call and I want to change the output into option. I have select tags where I want to append these options
<div class="views-element-container">
<div class="view view-contact-view-id-contact view-display-id-page_2 js-view-dom-id">
<div class="view-content">
1009abc example 1008xyz example 12564abc cdfg & TOT arrangement
</div>
</div>
</div>
now I want output:
<option value="1009">abc example </option>
<option value="1008">xyz example </option>
<option value="12564">abc cdfg & TOT arrangement</option>
2
Answers
You can use a fragment and a regexp
Using jQuery you can achieve it like this:
a) Get the desired div content first.
b) Match this content with the appropriate regular expression so that it will give you an array of strings.
c) Apply loop over this array of string values
d) Again math the values with an appropriate regular expression so that you will get an array of digits and the rest of the string.
e) Use this digit value as the select option value and string as the select option text.
Working sample: