So I need to append and un-append divs which contain the values of whichever option was selected, problem is that the method of displaying the select values in the first place is via. a for-each loop using Smarty PHP templates, and I am unable to find any documentation on how it can be achieved using this.
What I've tried: as you will see below I've tried creating a JavaScript variable inside the template file, but it only ever returns the value of the first option selected. I cannot figure out why I am only ever getting the first value taken from the loop.
For example, if I have two items in a select 'A' and 'B', when selecting the value option, I will always just receive 'A' back as the value.
Smarty Template Code:
<select class="my_select" name="vlans_{$NetworkDTO->id}[]">
{foreach from=$arrNetworkDTO item=NetworkDTO name=arr}
<option class="addOvmCardList" id="addNameDisk{$strIdTpl}" value="{$NetworkDTO->name|escape}">{$NetworkDTO->name}</option>
{/foreach}
</select>
JQuery Code:
$('a.addListOVM').click(function(){
$(".my_select").change(function() {
$('.addCardOVM').append(
'<div class="divform"><label>' + $(this).val() + '</label>' +
'<a href="">-</a></div>'
);
});
});
Any help is appreciated.