I have a select menu and I'd like to add more select inputs dynamically. I found this solution: https://gist.github.com/snipe/1925906 and it works great without jQuery Mobile. But jQuery Mobile modifies elements and adds its own code. So before the select menu itself jQM adds such elements (and a few more but it isn't so important):
<span class='ui-btn-inner'><span class='ui-btn-text'><span>Option Name</span></span><span class='ui-icon ui-icon-arrow-d ui-icon-shadow'> </span></span>
This "Option Name" is already here and when I call the function, which uses "clone()" command, it clones this "Option Name" too. So, the first select menu works fine and its option name changes, but in the cloned menu it remains the same even when I choose another option.
Update: Here is my code (sorry for russian language in a few places). HTML with select and text inputs:
<fieldset class='ui-grid-a'>
<div id='inputphone1' class='clonedInputPhone'>
<div class='ui-block-a' style='max-width: 200px;'>
<select name='phone_type[]' data-mini='true'>
<option value="mobile">Мобильный</option>
<option value="home">Домашний</option>
<option value="work">Рабочий</option>
</select>
</div>
</div> <!-- inputphone1 -->
<div id='textinputphone1' class='textclonedInputPhone'>
<div class='ui-block-b'>
<input type='text' name='phone_number[]' data-mini='true' />
</div>
</div> <!-- textinputphone1 -->
</fieldset>
<fieldset class="ui-grid-a">
<div class="ui-block-a" style="max-width: 200px;">
</div>
<div class="ui-block-b">
<input id="btnAddPhone" type="button" data-icon="plus" data-iconpos="notext" data-inline="true" data-mini="true" onClick="addInput('phone_type', 'phone_number', 'clonedInputPhone', 'inputphone', 'btnAddPhone', 'btnDelPhone', '7', '0');" />
<input id="btnDelPhone" type="button" data-icon="minus" data-iconpos="notext" data-inline="true" data-mini="true" disabled="disabled" onClick="removeInput('clonedInputPhone', 'inputphone', 'btnAddPhone', 'btnDelPhone');" />
</div>
</fieldset>
And js functions:
function addInput(selectName, textName, clonedInputName, inputName, btnAddName, btnDelName, limit, numstart){
// how many "duplicatable" input fields we currently have
var num = $('.' + clonedInputName).length;
$('#' + btnDelName).removeAttr('disabled').button('enable');
// the numeric ID of the new input field being added
var newNum = new Number(num + 1);
var newSelect = $('#' + inputName + num ).clone().attr('id', inputName + newNum);
$('#text' + inputName + num).after(newSelect);
var newText = document.createElement('div');
newText.id = 'text' + inputName + newNum;
newText.className = 'text' + clonedInputName;
newText.innerHTML = "<div class='ui-block-b'><div class='ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-c ui-mini'><input type='text' name='" + textName + "[]' data-mini='true' class='ui-input-text ui-body-c'></div></div>";
$(newSelect).after(newText);
if (newNum == limit - numstart) {
$('#' + btnAddName ).prop('disabled', 'disabled').button('disable');
}
};
function removeInput(clonedInputName, inputName, btnAddName, btnDelName){
// how many "duplicatable" input fields we currently have
var num = $('.' + clonedInputName).length;
// remove the last element
$('#' + inputName + num ).remove();
$('#text' + inputName + num ).remove();
// enable the "add" button, since we've removed one
$('#' + btnAddName).removeAttr('disabled').button('enable');
// if only one element remains, disable the "remove" button
if ( num - 1 == 1)
$('#' + btnDelName ).prop('disabled', 'disabled').button('disable');
};
Because I cannot upload a screenshot, here it is: http://d.pr/i/choo The label "Мобильный" in the second select menu doesn't change, because it's written in the "span" which was cloned.
Any ideas how to solve this problem? Thank you!